File tree Expand file tree Collapse file tree
src/java.desktop/macosx/native Expand file tree Collapse file tree Original file line number Diff line number Diff line change 116116(CGDirectDisplayID displayId, CGDisplayChangeSummaryFlags flags, void *userInfo)
117117{
118118AWT_ASSERT_APPKIT_THREAD;
119+ JNIEnv *env = [ThreadUtilities getJNIEnv ];
119120JNI_COCOA_ENTER (env);
120121
121122 if (TRACE_DISPLAY_CALLBACKS) {
152153 block: ^()
153154 {
154155 @try {
155- JNIEnv *env = [ThreadUtilities getJNIEnv ];
156156 jobject graphicsEnv = (*env)->NewLocalRef (env, cgeRef);
157157 if (graphicsEnv == NULL ) return ; // ref already GC'd
158158 DECLARE_CLASS (jc_CGraphicsEnvironment, " sun/awt/CGraphicsEnvironment" );
173173
174174 // braces to reduce variable scope
175175 {
176- JNIEnv *env = [ThreadUtilities getJNIEnv ];
177176 jobject graphicsEnv = (*env)->NewLocalRef (env, cgeRef);
178177 if (graphicsEnv == NULL ) return ; // ref already GC'd
179178 DECLARE_CLASS (jc_CGraphicsEnvironment, " sun/awt/CGraphicsEnvironment" );
Original file line number Diff line number Diff line change @@ -254,8 +254,11 @@ + (void)setAppkitThreadGroup:(jobject)group {
254254 * Note : if waiting cross-thread, possibly the stack allocated copy is accessible ?
255255 */
256256+ (void )invokeBlockCopy : (void (^)(void ))blockCopy {
257- blockCopy ();
258- Block_release (blockCopy);
257+ @try {
258+ blockCopy ();
259+ } @finally {
260+ Block_release (blockCopy);
261+ }
259262}
260263
261264+ (NSString *)getCaller : (NSString *)prefixSymbol {
@@ -780,9 +783,18 @@ - (void)processQueuedCallbacks {
780783 const NSUInteger count = [self .queue count ];
781784 if (count != 0 ) {
782785 for (NSUInteger i = 0 ; i < count; i++) {
783- void (^blockCopy)(void ) = (void (^)())[self .queue objectAtIndex: i];
784- // invoke callback:
785- [ThreadUtilities invokeBlockCopy: blockCopy];
786+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc ] init ];
787+ @try {
788+ void (^blockCopy)(void ) = (void (^)())[self .queue objectAtIndex: i];
789+ // invoke callback:
790+ [ThreadUtilities invokeBlockCopy: blockCopy];
791+ } @catch (NSException *exception) {
792+ // handle any exception to avoid crashing the main run loop:
793+ NSLog (@" Apple AWT Cocoa Exception: %@ " , [exception description ]);
794+ NSLog (@" Apple AWT Cocoa Exception callstack: %@ " , [exception callStackSymbols ]);
795+ } @finally {
796+ [pool drain ];
797+ }
786798 }
787799 // reset queue anyway:
788800 [self reset ];
You can’t perform that action at this time.
0 commit comments