openFrameworks icon indicating copy to clipboard operation
openFrameworks copied to clipboard

ofToggleFullscreen() crash when set fullscreen via window header's fullscreen button

Open thomasgeissl opened this issue 2 years ago • 6 comments

On osx, oF 0.11.2 my app crashes when i first set the window fullscreen via the window bar then call ofToggleFullscreen

2022-03-15 20:21:45.354 ofPackageManager[96562:4193583] NSWindowStyleMaskFullScreen cleared on a window outside of a full screen transition. Called from (
        0   AppKit                              0x00007fff22b92dca __25-[NSWindow setStyleMask:]_block_invoke + 125
        1   AppKit                              0x00007fff22b92cf3 NSPerformVisuallyAtomicChange + 132
        2   AppKit                              0x00007fff22b92c00 -[NSWindow setStyleMask:] + 170
        3   ofPackageManager                    0x0000000104e4971c _ZN15ofAppGLFWWindow13setFullscreenEb + 108
        4   ofPackageManager                    0x0000000104e4c474 _Z18ofToggleFullscreenv + 41
        5   ofPackageManager                    0x0000000104d778b9 _ZNSt3__110__function6__funcIZN7ofEventI11ofEventArgsNS_15recursive_mutexEE13make_functionIN8ofxImGui3GuiEEENS_10shared_ptrIN2of4priv8FunctionIS3_S4_EEEEPT_MSF_FvRS3_EiEUlPKvSH_E_NS_9allocatorISM_EEFbSL_SH_EEclEOSL_SH_ + 37
        6   ofPackageManager                    0x0000000104ea805f _ZN7ofEventI14ofKeyEventArgsNSt3__115recursive_mutexEE6notifyERS0_ + 149
        7   ofPackageManager                    0x0000000104ea65ea _ZN12ofCoreEvents14notifyKeyEventER14ofKeyEventArgs + 862
        8   ofPackageManager                    0x0000000104e48885 _ZN15ofAppGLFWWindow11keyboard_cbEP10GLFWwindowiiii + 1057
        9   ofPackageManager                    0x0000000104d8a7e4 _Z26ImGui_ImplGlfw_KeyCallbackP10GLFWwindowiiii + 40
        10  AppKit                              0x00007fff22ccb9c8 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 6482
        11  AppKit                              0x00007fff22cc9e56 -[NSWindow(NSEventRouting) sendEvent:] + 347
        12  ofPackageManager                    0x00000001053a1362 _glfwPlatformPollEvents + 146
        13  ofPackageManager                    0x0000000104e427ea _ZN10ofMainLoop4loopEv + 62
        14  ofPackageManager                    0x0000000104e4b271 _Z8ofRunAppP9ofBaseApp + 138
        15  ofPackageManager                    0x0000000104d1754c main + 720
        16  libdyld.dylib                       0x00007fff20339f5d start + 1
)
2022-03-15 20:21:45.357 ofPackageManager[96562:4193583] *** Terminating app due to uncaught exception 'NSGenericException', reason: 'NSWindowStyleMaskFullScreen cleared on a window outside of a full screen transition. Called from (
        0   AppKit                              0x00007fff22b92dca __25-[NSWindow setStyleMask:]_block_invoke + 125
        1   AppKit                              0x00007fff22b92cf3 NSPerformVisuallyAtomicChange + 132
        2   AppKit                              0x00007fff22b92c00 -[NSWindow setStyleMask:] + 170
        3   ofPackageManager                    0x0000000104e4971c _ZN15ofAppGLFWWindow13setFullscreenEb + 108
        4   ofPackageManager                    0x0000000104e4c474 _Z18ofToggleFullscreenv + 41
        5   ofPackageManager                    0x0000000104d778b9 _ZNSt3__110__function6__funcIZN7ofEventI11ofEventArgsNS_15recursive_mutexEE13make_functionIN8ofxImGui3GuiEEENS_10shared_ptrIN2of4priv8FunctionIS3_S4_EEEEPT_MSF_FvRS3_EiEUlPKvSH_E_NS_9allocatorISM_EEFbSL_SH_EEclEOSL_SH_ + 37
        6   ofPackageManager                    0x0000000104ea805f _ZN7ofEventI14ofKeyEventArgsNSt3__115recursive_mutexEE6notifyERS0_ + 149
        7   ofPackageManager                    0x0000000104ea65ea _ZN12ofCoreEvents14notifyKeyEventER14ofKeyEventArgs + 862
        8   ofPackageManager                    0x0000000104e48885 _ZN15ofAppGLFWWindow11keyboard_cbEP10GLFWwindowiiii + 1057
        9   ofPackageManager                    0x0000000104d8a7e4 _Z26ImGui_ImplGlfw_KeyCallbackP10GLFWwindowiiii + 40
        10  AppKit                              0x00007fff22ccb9c8 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 6482
        11  AppKit                              0x00007fff22cc9e56 -[NSWindow(NSEventRouting) sendEvent:] + 347
        12  ofPackageManager                    0x00000001053a1362 _glfwPlatformPollEvents + 146
        13  ofPackageManager                    0x0000000104e427ea _ZN10ofMainLoop4loopEv + 62
        14  ofPackageManager                    0x0000000104e4b271 _Z8ofRunAppP9ofBaseApp + 138
        15  ofPackageManager                    0x0000000104d1754c main + 720
        16  libdyld.dylib                       0x00007fff20339f5d start + 1
)'
*** First throw call stack:
(
        0   CoreFoundation                      0x00007fff204914bf __exceptionPreprocess + 242
        1   libobjc.A.dylib                     0x00007fff201c9bbb objc_exception_throw + 48
        2   CoreFoundation                      0x00007fff20491323 +[NSException raise:format:] + 181
        3   AppKit                              0x00007fff22b92e07 __25-[NSWindow setStyleMask:]_block_invoke + 186
        4   AppKit                              0x00007fff22b92cf3 NSPerformVisuallyAtomicChange + 132
        5   AppKit                              0x00007fff22b92c00 -[NSWindow setStyleMask:] + 170
        6   ofPackageManager                    0x0000000104e4971c _ZN15ofAppGLFWWindow13setFullscreenEb + 108
        7   ofPackageManager                    0x0000000104e4c474 _Z18ofToggleFullscreenv + 41
        8   ofPackageManager                    0x0000000104d778b9 _ZNSt3__110__function6__funcIZN7ofEventI11ofEventArgsNS_15recursive_mutexEE13make_functionIN8ofxImGui3GuiEEENS_10shared_ptrIN2of4priv8FunctionIS3_S4_EEEEPT_MSF_FvRS3_EiEUlPKvSH_E_NS_9allocatorISM_EEFbSL_SH_EEclEOSL_SH_ + 37
        9   ofPackageManager                    0x0000000104ea805f _ZN7ofEventI14ofKeyEventArgsNSt3__115recursive_mutexEE6notifyERS0_ + 149
        10  ofPackageManager                    0x0000000104ea65ea _ZN12ofCoreEvents14notifyKeyEventER14ofKeyEventArgs + 862
        11  ofPackageManager                    0x0000000104e48885 _ZN15ofAppGLFWWindow11keyboard_cbEP10GLFWwindowiiii + 1057
        12  ofPackageManager                    0x0000000104d8a7e4 _Z26ImGui_ImplGlfw_KeyCallbackP10GLFWwindowiiii + 40
        13  AppKit                              0x00007fff22ccb9c8 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 6482
        14  AppKit                              0x00007fff22cc9e56 -[NSWindow(NSEventRouting) sendEvent:] + 347
        15  ofPackageManager                    0x00000001053a1362 _glfwPlatformPollEvents + 146
        16  ofPackageManager                    0x0000000104e427ea _ZN10ofMainLoop4loopEv + 62
        17  ofPackageManager                    0x0000000104e4b271 _Z8ofRunAppP9ofBaseApp + 138
        18  ofPackageManager                    0x0000000104d1754c main + 720
        19  libdyld.dylib                       0x00007fff20339f5d start + 1
)
libc++abi: terminating with uncaught exception of type NSException
/bin/sh: line 1: 96562 Abort trap: 6           ./ofPackag

thomasgeissl avatar Mar 15 '22 19:03 thomasgeissl

Ah, I am guessing that OF still thinks the app is in windowed mode and then incorrectly makes fullscreen changes which cause the crash.

We might want to see if we can detect when the window is made fullscreen outside of OF. If we can do that then I imagine it will fix this sort of crash.

ofTheo avatar Mar 15 '22 19:03 ofTheo

@thomasgeissl okay to assign you to this issue?

ofTheo avatar Mar 15 '22 19:03 ofTheo

sure. I will have a look and probably tons of questions will come up. I think there was also an issue not being able to query if the app is in fullscreen mode or not, not sure I remember correctly.

thomasgeissl avatar Mar 15 '22 20:03 thomasgeissl

I could kinda fix this one switching two lines of cocoaWindow setStyleMask to the following

		[cocoaWindow toggleFullScreen:cocoaWindow];

it doesn't break anymore but it is still confused when window have to be resized to the screen or not. it can be fixed with a getter of cocoaWindow fullscreen or not.

dimitre avatar Apr 17 '22 21:04 dimitre

It can be fixed if we add this lines to the start of ofAppGLFWWindow::setFullscreen function

#ifdef TARGET_OSX
	NSWindow * cocoaWindow = glfwGetCocoaWindow(windowP);
	if (([cocoaWindow styleMask] & NSFullScreenWindowMask) == NSFullScreenWindowMask) {
		settings.windowMode = OF_FULLSCREEN;
	} else {
		settings.windowMode = OF_WINDOW;
	}

#endif 

so it updates settings.windowMode before anything. It solves the crash, maybe we have to add a test to see if it is not OF_GAME_MODE before.

The thing is : maximize by the green button is different than OF fullscreen, it is animated, the second window becames black (as if it is using another space) and in my computer it shows a black bar as if the second monitor had the webcam bezel. Ah and the window maximization is "animated".

Another thing interesting to add in setFullscreen function is no shadow if fullscreen, with shadow if windowed. I've noticed the shadow bleeds to the second monitor

	[cocoaWindow setHasShadow:NO];

there is a way of graying out the green button too.

dimitre avatar Apr 27 '22 22:04 dimitre

hey @dimitre, thanks for figuring this out. I am packed with work at the moment and havent had the time (nor the brain) to look into this. i remember that i had problems when i started an app with command line args to set the window mode. There was no easy way like an ofIsFullScreen or similar to check if the app is running in fullscreen. I was wondering if such a function could be added and used internally by the ofToggleFullscreen

thomasgeissl avatar Apr 28 '22 15:04 thomasgeissl

closed by https://github.com/openframeworks/openFrameworks/pull/7538#event-9119259834

dimitre avatar Apr 27 '23 22:04 dimitre