diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2023-07-07 08:32:56 +0200 |
|---|---|---|
| committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-07-07 08:32:56 +0200 |
| commit | 9522ef67d5ddfdf00d8d52bcf26dedbb5545cb37 (patch) | |
| tree | 5ce91055caadfb91a5e3401c88e2d7a2c3d1e887 | |
| parent | ecca4e5e2f8bd650498878b9b7f90513b78311d6 (diff) | |
| parent | 618795a214cf8f34c60190d754536fd060664121 (diff) | |
| download | redot-engine-9522ef67d5ddfdf00d8d52bcf26dedbb5545cb37.tar.gz | |
Merge pull request #79010 from bruvzg/set_native_icon_crash
[macOS] Fix `set_native_icon` crash with empty or invalid ICNS file.
| -rw-r--r-- | platform/macos/display_server_macos.mm | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm index 973925a003..5ccef68e7f 100644 --- a/platform/macos/display_server_macos.mm +++ b/platform/macos/display_server_macos.mm @@ -3588,16 +3588,22 @@ void DisplayServerMacOS::set_native_icon(const String &p_filename) { Vector<uint8_t> data; uint64_t len = f->get_length(); + ERR_FAIL_COND_MSG(len < 8, "Error reading icon data."); // "icns" + 32-bit length + data.resize(len); f->get_buffer((uint8_t *)&data.write[0], len); - NSData *icon_data = [[NSData alloc] initWithBytes:&data.write[0] length:len]; - ERR_FAIL_COND_MSG(!icon_data, "Error reading icon data."); + @try { + NSData *icon_data = [[NSData alloc] initWithBytes:&data.write[0] length:len]; + ERR_FAIL_COND_MSG(!icon_data, "Error reading icon data."); - NSImage *icon = [[NSImage alloc] initWithData:icon_data]; - ERR_FAIL_COND_MSG(!icon, "Error loading icon."); + NSImage *icon = [[NSImage alloc] initWithData:icon_data]; + 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) { |
