Error reported on MacOS
Closed this issue · 2 comments
import 'dart:ffi';
import 'package:ffi/ffi.dart';
import 'package:sdl2/sdl2.dart';
int main() {
if (SDL_Init(SDL_INIT_VIDEO) == 0) {
SDL_CreateWindow("SDL Demo",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN);
bool quit = false;
var event = calloc<SDL_Event>();
while(!quit){
while(SDL_PollEvent(event) == 0){
if(event.type == SDL_QUIT){
quit = true;
}
}
}
SDL_Quit();
}
return 0;
}
Run the above code on MacOS, it will report an error:
dart[32147:300082] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'nextEventMatchingMask should only be called from the Main Thread!'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff205a46af __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007fff202dc3c9 objc_exception_throw + 48
2 AppKit 0x00007fff22d47d3c -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 4379
3 libSDL2-2.0.0.dylib 0x000000011a232eb6 Cocoa_PumpEventsUntilDate + 88
4 libSDL2-2.0.0.dylib 0x000000011a232fc8 Cocoa_PumpEvents + 47
5 libSDL2-2.0.0.dylib 0x000000011a1a2004 SDL_PumpEvents_REAL + 33
6 libSDL2-2.0.0.dylib 0x000000011a1a20e2 SDL_WaitEventTimeout_REAL + 171
7 ??? 0x000000011138587b 0x0 + 4583872635
8 ??? 0x00000001167a9b83 0x0 + 4672101251
9 ??? 0x00000001167a9ab2 0x0 + 4672101042
)
libc++abi.dylib: terminating with uncaught exception of type NSException
This is because the SDL_PollEvent
method is called, and no error will be reported if this method is not called. But rewriting the above code in C language will not cause any problems.
Thank you for the issue.
[update] Support SDL version 2.0.20 (stable)
Multi platform support.
https://github.com/sansuido/sdl2/blob/main/lib/sdl2/dylib.dart
If it's an IOS environment, it will refer to libSDL2.dylib, but I don't have an IOS environment so I haven't tried it, sorry.