-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added new method set_window_icon for macos, windows, html5 platform #71
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested for bundled Windows and HTML5
Why not accept an absolute path into that function? (on macOS) That way it can be consistent with What's really missing, though, is a function to get the absolute path to the bundle root. I made something similar here: https://github.com/dapetcu21/defold-fmod/blob/master/bridge/src/fmod_dynamic_loading.cpp#L76 |
I see that for HTML5 and Windows you're passing the path directly and it would be relative to the current directory, which is not guaranteed to be the same as the directory containing your executable. |
I saw how did you work with cursor, and I don't' want to work this way with icon. |
Yes, yet it's confusing to be using absolute paths in one place and relative paths in another place. Furthermore, on Windows the path is not even relative to the right thing. You want it to be relative to the game's .exe, not to the current directory. |
how do you propose to fix that? |
Add a
(see what I linked above) |
I like this solution, I'll implement it soon |
You should also add a |
I can return path already with separator |
defos/src/defos_mac.mm
Outdated
void defos_set_window_icon(const char *icon_path) | ||
{ | ||
NSString *bundlePath = [[NSBundle mainBundle] resourcePath]; | ||
NSString *secondParentPath = [[bundlePath stringByDeletingLastPathComponent] stringByDeletingLastPathComponent]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could have gotten to this in a more easier way:
[[NSBundle mainBundle] bundlePath]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, thx.
Please don't return it with separator. The user might want to use it for something else as well. And they might want to compose their own path, so having the separator separately is helpful. |
@dapetcu21 done. |
|
defos/src/defos_html5.cpp
Outdated
document.head || (document.head = document.getElementsByTagName('head')[0]); | ||
function changeFavicon(src) { | ||
var link = document.createElement('link'); | ||
var oldLink = document.getElementById('dynamic-favicon'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the user has a <link rel='shortcut icon'>
already in the document that wasn't inserted by defos, he'll end up having two <link>
's. Maybe do var oldLink = document.querySelector('link[rel="shortcut icon"]')
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
stringToUTF8(jsString, stringOnWasmHeap, lengthBytes+1); | ||
return stringOnWasmHeap; | ||
},0); | ||
return bundlePath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This leaks the bundlePath
string after it gets passed to Lua in get_bundle_root()
. Maybe always make sure we return a string we own and free()
it in get_bundle_root()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to do this (I asked you aboutt free()), it was my fault with const, thx!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
defos/src/defos_mac.mm
Outdated
void defos_set_window_icon(const char *icon_path) | ||
{ | ||
NSString *path = [NSString stringWithUTF8String:icon_path]; | ||
NSImage* image = [[NSImage alloc] initWithContentsOfFile: path]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This image
leaks. It needs to be released after giving it to the window button.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
defos/src/defos_win.cpp
Outdated
char const* defos_get_bundle_root() { | ||
char bundlePath[MAX_PATH]; | ||
GetCurrentDirectory(MAX_PATH, bundlePath); | ||
return bundlePath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're returning a reference to a string on the stack, which will be invalid memory after this function returns. Allocate memory for the string and make sure it gets freed after passing it to Lua
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
defos/src/defos_mac.mm
Outdated
@@ -93,6 +93,20 @@ void defos_set_window_title(const char* title_lua) { | |||
[window setTitle:title]; | |||
} | |||
|
|||
void defos_set_window_icon(const char *icon_path) | |||
{ | |||
NSString *path = [NSString stringWithUTF8String:icon_path]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This string gets created and autoreleased, meaning it will get garbage collected by the nearest autorelease pool. We don't know how Defold works internally, so we don't know if it has an autorelease pool in all contexts this function might get called. It would be safest to surround this with an @autorelease { ... }
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, i'll do this. thx.
I think Defold has no autorelease pool in all context, i found this issue with other my NE :
https://forum.defold.com/t/native-extensions/4946/149?u=agulev
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
defos/src/defos_mac.mm
Outdated
char const* defos_get_bundle_root() { | ||
NSString *bundlePath = [[NSBundle mainBundle] bundlePath]; | ||
const char *bundlePath_lua = [bundlePath UTF8String]; | ||
return bundlePath_lua; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine. It won't leak since it's owned by the bundle, but if we add a free()
in get_bundle_root()
as I suggested for HTML and Windows, we should copy this string into some memory we own.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
try to find <link> in html5 realisation before creation of new icon
No description provided.