From 7e76df3a05b7eb2404cb4584ee0b34ea287eb9bf Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 9 Sep 2019 09:36:50 +0200 Subject: Bug 1393: OSXUtil: Optionally inject Apple's 'Main Thread Checker' To allow proper testing of whether all AppKit calls are performed on its Main-Thread where required, we inject the libMainThreadChecker.dylib when property 'nativewindow.debug.OSXUtil.MainThreadChecker' is set. See Lib-Name: /Applications/Xcode.app/Contents/Developer/usr/lib/libMainThreadChecker.dylib --- .../jogamp/nativewindow/macosx/OSXUtil.java | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/nativewindow/classes') diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java index 196cdff57..f84955e69 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java @@ -31,6 +31,11 @@ import com.jogamp.nativewindow.NativeWindowException; import com.jogamp.nativewindow.NativeWindowFactory; import com.jogamp.nativewindow.util.Insets; import com.jogamp.nativewindow.util.Point; + +import java.security.AccessController; +import java.security.PrivilegedAction; + +import com.jogamp.common.os.NativeLibrary; import com.jogamp.common.util.Function; import com.jogamp.common.util.FunctionTask; import com.jogamp.common.util.InterruptedRuntimeException; @@ -55,12 +60,26 @@ public class OSXUtil implements ToolkitProperties { */ public static synchronized void initSingleton() { if(!isInit) { - if(DEBUG) { - System.out.println("OSXUtil.initSingleton()"); + final boolean useMainThreadChecker = Debug.debug("OSXUtil.MainThreadChecker"); + if(DEBUG || useMainThreadChecker) { + System.out.println("OSXUtil.initSingleton() - useMainThreadChecker "+useMainThreadChecker); } if(!NWJNILibLoader.loadNativeWindow("macosx")) { throw new NativeWindowException("NativeWindow MacOSX native library load error."); } + if( useMainThreadChecker ) { + final String libMainThreadChecker = "/Applications/Xcode.app/Contents/Developer/usr/lib/libMainThreadChecker.dylib"; + final NativeLibrary lib = AccessController.doPrivileged(new PrivilegedAction() { + @Override + public NativeLibrary run() { + return NativeLibrary.open(libMainThreadChecker, false, false, OSXUtil.class.getClassLoader(), true); + } } ); + if( null == lib ) { + System.err.println("Could not load "+libMainThreadChecker); + } else { + System.err.println("Loaded "+lib); + } + } if( !initIDs0() ) { throw new NativeWindowException("MacOSX: Could not initialized native stub"); -- cgit v1.2.3