Merge pull request #79010 from bruvzg/set_native_icon_crash
[macOS] Fix `set_native_icon` crash with empty or invalid ICNS file.
This commit is contained in:
commit
9522ef67d5
1 changed files with 11 additions and 5 deletions
|
@ -3588,9 +3588,12 @@ void DisplayServerMacOS::set_native_icon(const String &p_filename) {
|
||||||
|
|
||||||
Vector<uint8_t> data;
|
Vector<uint8_t> data;
|
||||||
uint64_t len = f->get_length();
|
uint64_t len = f->get_length();
|
||||||
|
ERR_FAIL_COND_MSG(len < 8, "Error reading icon data."); // "icns" + 32-bit length
|
||||||
|
|
||||||
data.resize(len);
|
data.resize(len);
|
||||||
f->get_buffer((uint8_t *)&data.write[0], len);
|
f->get_buffer((uint8_t *)&data.write[0], len);
|
||||||
|
|
||||||
|
@try {
|
||||||
NSData *icon_data = [[NSData alloc] initWithBytes:&data.write[0] length:len];
|
NSData *icon_data = [[NSData alloc] initWithBytes:&data.write[0] length:len];
|
||||||
ERR_FAIL_COND_MSG(!icon_data, "Error reading icon data.");
|
ERR_FAIL_COND_MSG(!icon_data, "Error reading icon data.");
|
||||||
|
|
||||||
|
@ -3598,6 +3601,9 @@ void DisplayServerMacOS::set_native_icon(const String &p_filename) {
|
||||||
ERR_FAIL_COND_MSG(!icon, "Error loading icon.");
|
ERR_FAIL_COND_MSG(!icon, "Error loading icon.");
|
||||||
|
|
||||||
[NSApp setApplicationIconImage:icon];
|
[NSApp setApplicationIconImage:icon];
|
||||||
|
} @catch (NSException *exception) {
|
||||||
|
ERR_FAIL_MSG("NSException: " + String::utf8([exception reason].UTF8String));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisplayServerMacOS::set_icon(const Ref<Image> &p_icon) {
|
void DisplayServerMacOS::set_icon(const Ref<Image> &p_icon) {
|
||||||
|
|
Loading…
Reference in a new issue