diff options
Diffstat (limited to 'platform/osx')
-rw-r--r-- | platform/osx/detect.py | 1 | ||||
-rw-r--r-- | platform/osx/display_server_osx.mm | 36 | ||||
-rw-r--r-- | platform/osx/export/codesign.cpp | 2 | ||||
-rw-r--r-- | platform/osx/export/export_plugin.cpp | 3 | ||||
-rw-r--r-- | platform/osx/export/plist.cpp | 1 | ||||
-rw-r--r-- | platform/osx/godot_main_osx.mm | 10 | ||||
-rw-r--r-- | platform/osx/joypad_osx.cpp | 6 | ||||
-rw-r--r-- | platform/osx/joypad_osx.h | 2 | ||||
-rw-r--r-- | platform/osx/os_osx.mm | 33 |
9 files changed, 64 insertions, 30 deletions
diff --git a/platform/osx/detect.py b/platform/osx/detect.py index 0ff93bedb4..8d848d2094 100644 --- a/platform/osx/detect.py +++ b/platform/osx/detect.py @@ -127,6 +127,7 @@ def configure(env): if env["use_ubsan"] or env["use_asan"] or env["use_tsan"]: env.extra_suffix += ".san" + env.Append(CCFLAGS=["-DSANITIZERS_ENABLED"]) if env["use_ubsan"]: env.Append( diff --git a/platform/osx/display_server_osx.mm b/platform/osx/display_server_osx.mm index 6cdadcae39..986c711fc9 100644 --- a/platform/osx/display_server_osx.mm +++ b/platform/osx/display_server_osx.mm @@ -3000,21 +3000,25 @@ Rect2i DisplayServerOSX::window_get_popup_safe_rect(WindowID p_window) const { } void DisplayServerOSX::popup_open(WindowID p_window) { + _THREAD_SAFE_METHOD_ + WindowData &wd = windows[p_window]; if (wd.is_popup) { bool was_empty = popup_list.is_empty(); - // Close all popups, up to current popup parent, or every popup if new window is not transient. + // Find current popup parent, or root popup if new window is not transient. + List<WindowID>::Element *C = nullptr; List<WindowID>::Element *E = popup_list.back(); while (E) { if (wd.transient_parent != E->get() || wd.transient_parent == INVALID_WINDOW_ID) { - send_window_event(windows[E->get()], DisplayServerOSX::WINDOW_EVENT_CLOSE_REQUEST); - List<WindowID>::Element *F = E->prev(); - popup_list.erase(E); - E = F; + C = E; + E = E->prev(); } else { break; } } + if (C) { + send_window_event(windows[C->get()], DisplayServerOSX::WINDOW_EVENT_CLOSE_REQUEST); + } if (was_empty && popup_list.is_empty()) { // Inform OS that popup was opened, to close other native popups. @@ -3026,12 +3030,16 @@ void DisplayServerOSX::popup_open(WindowID p_window) { } void DisplayServerOSX::popup_close(WindowID p_window) { + _THREAD_SAFE_METHOD_ + bool was_empty = popup_list.is_empty(); List<WindowID>::Element *E = popup_list.find(p_window); while (E) { - send_window_event(windows[E->get()], DisplayServerOSX::WINDOW_EVENT_CLOSE_REQUEST); List<WindowID>::Element *F = E->next(); + WindowID win_id = E->get(); popup_list.erase(E); + + send_window_event(windows[win_id], DisplayServerOSX::WINDOW_EVENT_CLOSE_REQUEST); E = F; } if (!was_empty && popup_list.is_empty()) { @@ -3047,11 +3055,8 @@ void DisplayServerOSX::mouse_process_popups(bool p_close) { if (p_close) { // Close all popups. List<WindowID>::Element *E = popup_list.front(); - while (E) { + if (E) { send_window_event(windows[E->get()], DisplayServerOSX::WINDOW_EVENT_CLOSE_REQUEST); - List<WindowID>::Element *F = E->next(); - popup_list.erase(E); - E = F; } if (!was_empty) { // Inform OS that all popups are closed. @@ -3064,7 +3069,9 @@ void DisplayServerOSX::mouse_process_popups(bool p_close) { } Point2i pos = mouse_get_position(); + List<WindowID>::Element *C = nullptr; List<WindowID>::Element *E = popup_list.back(); + // Find top popup to close. while (E) { // Popup window area. Rect2i win_rect = Rect2i(window_get_position(E->get()), window_get_size(E->get())); @@ -3075,12 +3082,13 @@ void DisplayServerOSX::mouse_process_popups(bool p_close) { } else if (safe_rect != Rect2i() && safe_rect.has_point(pos)) { break; } else { - send_window_event(windows[E->get()], DisplayServerOSX::WINDOW_EVENT_CLOSE_REQUEST); - List<WindowID>::Element *F = E->prev(); - popup_list.erase(E); - E = F; + C = E; + E = E->prev(); } } + if (C) { + send_window_event(windows[C->get()], DisplayServerOSX::WINDOW_EVENT_CLOSE_REQUEST); + } if (!was_empty && popup_list.is_empty()) { // Inform OS that all popups are closed. [[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"com.apple.HIToolbox.endMenuTrackingNotification" object:@"org.godotengine.godot.popup_window"]; diff --git a/platform/osx/export/codesign.cpp b/platform/osx/export/codesign.cpp index b609a21c44..dab9f3eccb 100644 --- a/platform/osx/export/codesign.cpp +++ b/platform/osx/export/codesign.cpp @@ -947,7 +947,7 @@ CodeSignCodeDirectory::CodeSignCodeDirectory(uint8_t p_hash_size, uint8_t p_hash } blob.resize(cd_size); memset(blob.ptrw() + 8, 0x00, cd_size - 8); - CodeDirectoryHeader *cd = (CodeDirectoryHeader *)(blob.ptrw() + 8); + CodeDirectoryHeader *cd = reinterpret_cast<CodeDirectoryHeader *>(blob.ptrw() + 8); bool is_64_cl = (p_code_limit >= std::numeric_limits<uint32_t>::max()); diff --git a/platform/osx/export/export_plugin.cpp b/platform/osx/export/export_plugin.cpp index 4f06342fac..682f722a85 100644 --- a/platform/osx/export/export_plugin.cpp +++ b/platform/osx/export/export_plugin.cpp @@ -935,6 +935,9 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p unz_file_info info; char fname[16384]; ret = unzGetCurrentFileInfo(src_pkg_zip, &info, fname, 16384, nullptr, 0, nullptr, 0); + if (ret != UNZ_OK) { + break; + } String file = String::utf8(fname); diff --git a/platform/osx/export/plist.cpp b/platform/osx/export/plist.cpp index 553b864180..3580ad877d 100644 --- a/platform/osx/export/plist.cpp +++ b/platform/osx/export/plist.cpp @@ -398,7 +398,6 @@ bool PList::load_string(const String &p_string) { } if (token == "/plist") { - in_plist = false; done_plist = true; break; } diff --git a/platform/osx/godot_main_osx.mm b/platform/osx/godot_main_osx.mm index f3db363151..053a7f4a1d 100644 --- a/platform/osx/godot_main_osx.mm +++ b/platform/osx/godot_main_osx.mm @@ -35,12 +35,22 @@ #include <string.h> #include <unistd.h> +#if defined(SANITIZERS_ENABLED) +#include <sys/resource.h> +#endif + int main(int argc, char **argv) { #if defined(VULKAN_ENABLED) // MoltenVK - enable full component swizzling support. setenv("MVK_CONFIG_FULL_IMAGE_VIEW_SWIZZLE", "1", 1); #endif +#if defined(SANITIZERS_ENABLED) + // Note: Set stack size to be at least 30 MB (vs 8 MB default) to avoid overflow, address sanitizer can increase stack usage up to 3 times. + struct rlimit stack_lim = { 0x1E00000, 0x1E00000 }; + setrlimit(RLIMIT_STACK, &stack_lim); +#endif + int first_arg = 1; const char *dbg_arg = "-NSDocumentRevisionsDebugMode"; printf("arguments\n"); diff --git a/platform/osx/joypad_osx.cpp b/platform/osx/joypad_osx.cpp index 7d31ede61d..be9567e17c 100644 --- a/platform/osx/joypad_osx.cpp +++ b/platform/osx/joypad_osx.cpp @@ -195,7 +195,7 @@ void joypad::add_hid_element(IOHIDElementRef p_element) { } static void hid_element_added(const void *p_value, void *p_parameter) { - joypad *joy = (joypad *)p_parameter; + joypad *joy = static_cast<joypad *>(p_parameter); joy->add_hid_element((IOHIDElementRef)p_value); } @@ -540,10 +540,10 @@ static CFDictionaryRef create_match_dictionary(const UInt32 page, const UInt32 u CFDictionaryRef retval = nullptr; CFNumberRef pageNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &page); CFNumberRef usageNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage); - const void *keys[2] = { (void *)CFSTR(kIOHIDDeviceUsagePageKey), (void *)CFSTR(kIOHIDDeviceUsageKey) }; - const void *vals[2] = { (void *)pageNumRef, (void *)usageNumRef }; if (pageNumRef && usageNumRef) { + const void *keys[2] = { (void *)CFSTR(kIOHIDDeviceUsagePageKey), (void *)CFSTR(kIOHIDDeviceUsageKey) }; + const void *vals[2] = { (void *)pageNumRef, (void *)usageNumRef }; retval = CFDictionaryCreate(kCFAllocatorDefault, keys, vals, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); } diff --git a/platform/osx/joypad_osx.h b/platform/osx/joypad_osx.h index 4ca7fb1698..b09d5ce34a 100644 --- a/platform/osx/joypad_osx.h +++ b/platform/osx/joypad_osx.h @@ -94,7 +94,7 @@ class JoypadOSX { }; private: - Input *input; + Input *input = nullptr; IOHIDManagerRef hid_manager; Vector<joypad> device_list; diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 7e0cf9f9cc..afbd338832 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -313,21 +313,22 @@ String OS_OSX::get_executable_path() const { } Error OS_OSX::create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id, bool p_open_console) { - if (@available(macOS 10.15, *)) { - // Use NSWorkspace if path is an .app bundle. - NSURL *url = [NSURL fileURLWithPath:@(p_path.utf8().get_data())]; - NSBundle *bundle = [NSBundle bundleWithURL:url]; - if (bundle) { - NSMutableArray *arguments = [[NSMutableArray alloc] init]; - for (const List<String>::Element *E = p_arguments.front(); E; E = E->next()) { - [arguments addObject:[NSString stringWithUTF8String:E->get().utf8().get_data()]]; - } + // Use NSWorkspace if path is an .app bundle. + NSURL *url = [NSURL fileURLWithPath:@(p_path.utf8().get_data())]; + NSBundle *bundle = [NSBundle bundleWithURL:url]; + if (bundle) { + NSMutableArray *arguments = [[NSMutableArray alloc] init]; + for (const String &arg : p_arguments) { + [arguments addObject:[NSString stringWithUTF8String:arg.utf8().get_data()]]; + } + if (@available(macOS 10.15, *)) { NSWorkspaceOpenConfiguration *configuration = [[NSWorkspaceOpenConfiguration alloc] init]; [configuration setArguments:arguments]; [configuration setCreatesNewApplicationInstance:YES]; __block dispatch_semaphore_t lock = dispatch_semaphore_create(0); __block Error err = ERR_TIMEOUT; __block pid_t pid = 0; + [[NSWorkspace sharedWorkspace] openApplicationAtURL:url configuration:configuration completionHandler:^(NSRunningApplication *app, NSError *error) { @@ -350,7 +351,19 @@ Error OS_OSX::create_process(const String &p_path, const List<String> &p_argumen return err; } else { - return OS_Unix::create_process(p_path, p_arguments, r_child_id, p_open_console); + Error err = ERR_TIMEOUT; + NSError *error = nullptr; + NSRunningApplication *app = [[NSWorkspace sharedWorkspace] launchApplicationAtURL:url options:NSWorkspaceLaunchNewInstance configuration:[NSDictionary dictionaryWithObject:arguments forKey:NSWorkspaceLaunchConfigurationArguments] error:&error]; + if (error) { + err = ERR_CANT_FORK; + NSLog(@"Failed to execute: %@", error.localizedDescription); + } else { + if (r_child_id) { + *r_child_id = (ProcessID)[app processIdentifier]; + } + err = OK; + } + return err; } } else { return OS_Unix::create_process(p_path, p_arguments, r_child_id, p_open_console); |