Snipes icon indicating copy to clipboard operation
Snipes copied to clipboard

Terminating app due to uncaught exception 'NSInternalInconsistencyException'

Open johnhcc opened this issue 7 years ago • 4 comments

I'm running Mac OS 10.12.6. Building proceeds fine, but at runtime I'm getting the error Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'nextEventMatchingMask should only be called from the Main Thread!'.

Searching on this issue results in a lot of results, but not a lot of solutions, related to events/graphics calls being made outside the main thread.

Full error follows; thanks for any thoughts or ideas.

> ./snipes
2018-01-29 23:39:36.891 snipes[7435:42033] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'nextEventMatchingMask should only be called from the Main Thread!'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff935632cb __exceptionPreprocess + 171
	1   libobjc.A.dylib                     0x00007fffa837a48d objc_exception_throw + 48
	2   AppKit                              0x00007fff9174ce82 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 4480
	3   libSDL2-2.0.0.dylib                 0x0000000109bc040c Cocoa_PumpEvents + 211
	4   libSDL2-2.0.0.dylib                 0x0000000109b5dca5 SDL_PumpEvents_REAL + 23
	5   libSDL2-2.0.0.dylib                 0x0000000109b5dd20 SDL_WaitEventTimeout_REAL + 76
	6   snipes                              0x0000000109ab1808 _ZL17ConsoleThreadFuncPv + 1112
	7   libSDL2-2.0.0.dylib                 0x0000000109b896f0 SDL_RunThread + 60
	8   libSDL2-2.0.0.dylib                 0x0000000109bc8b9b RunThread + 9
	9   libsystem_pthread.dylib             0x00007fffa8e7993b _pthread_body + 180
	10  libsystem_pthread.dylib             0x00007fffa8e79887 _pthread_body + 0
	11  libsystem_pthread.dylib             0x00007fffa8e7908d thread_start + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6

johnhcc avatar Jan 30 '18 06:01 johnhcc

Get this same stack trace immediately on launch, also on 10.12.6. From what I can tell from various search results this has been solved in other projects by moving all rendering to the main thread? But it sounds more like a bug in this port of SDL2 than in Snipes itself, unless the SDL2 documentation says that you can only render things from the main thread?

lifelike avatar Oct 27 '18 21:10 lifelike

Well, ostensibly this port is only for Windows and Linux; the fact that the code compiles and almost runs on OS X is an emergent effect of trying to avoid platform-specific code where reasonable. I don't think either @Davidebyzero or I have an OS X machine, so... patches welcome :)

The reason the SDL port does rendering in a different thread is because that's kind of how things happened in the DOS version, where programs simply wrote stuff to the video buffer at A0000 / B8000, and the GPU (its own piece of hardware, but here "emulated" as a different thread) picked up and rendered stuff from there.

CyberShadow avatar Oct 28 '18 16:10 CyberShadow

I don't think my C++ or SDL2 knowledge make it likely I will be able to fix this myself... but I will mess around with this for a while. I'm also more than happy to test any development branches if someone else feels like giving it a go.

As to what @lifelike wrote... this requirement that all rendering occur in the main thread is something MacOS started enforcing fairly recently (as revealed by a Google search of the error), and I don't know why they felt the need to step in and do this. I certainly understand why the rendering is done in a different thread in this case, given the historical nature of the software. It sounds like changing that is not a trivial task.

johnhcc avatar Oct 30 '18 05:10 johnhcc

If someone wants to have a go at this, the first thing I'd try is move the SDL_Init call from the OpenConsole function to inside the ConsoleThreadFunc function.

CyberShadow avatar Apr 14 '24 12:04 CyberShadow