From c1740e3636c7d9b4cf89d0a7bc07c29b480aa425 Mon Sep 17 00:00:00 2001 From: PatTheMav Date: Thu, 21 Jul 2022 18:35:44 +0200 Subject: [PATCH] UI: Add initialization to ensure compat between pthread and NSThread Ensures that Cocoa knows that we intend to use multiple threads, per https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/CreatingThreads/CreatingThreads.html#//apple_ref/doc/uid/10000057i-CH15-SW21 --- UI/obs-app.cpp | 1 + UI/platform-osx.mm | 9 +++++++++ UI/platform.hpp | 1 + 3 files changed, 11 insertions(+) diff --git a/UI/obs-app.cpp b/UI/obs-app.cpp index c3fdcc006..d058c0ee4 100644 --- a/UI/obs-app.cpp +++ b/UI/obs-app.cpp @@ -2070,6 +2070,7 @@ static int run_program(fstream &logFile, int argc, char *argv[]) #if __APPLE__ InstallNSApplicationSubclass(); + InstallNSThreadLocks(); if (!isInBundle()) { blog(LOG_ERROR, diff --git a/UI/platform-osx.mm b/UI/platform-osx.mm index 1a5ab3f13..23b4d28e5 100644 --- a/UI/platform-osx.mm +++ b/UI/platform-osx.mm @@ -278,6 +278,15 @@ void TaskbarOverlaySetStatus(TaskbarOverlayStatus status) } @end +void InstallNSThreadLocks() +{ + [[NSThread new] start]; + + if ([NSThread isMultiThreaded] != 1) { + abort(); + } +} + void InstallNSApplicationSubclass() { [OBSApplication sharedApplication]; diff --git a/UI/platform.hpp b/UI/platform.hpp index cef63d300..f65b31ca7 100644 --- a/UI/platform.hpp +++ b/UI/platform.hpp @@ -84,5 +84,6 @@ void EnableOSXVSync(bool enable); void EnableOSXDockIcon(bool enable); bool isInBundle(); void InstallNSApplicationSubclass(); +void InstallNSThreadLocks(); void disableColorSpaceConversion(QWidget *window); #endif