Skip to content

Commit 0fe6abf: SDL_PollEvent(NULL) in video.c causes crash on macOS  #52

@littlejackal

Description

@littlejackal

System:

  • macOS 14.6.1 (23G93), M1 Pro (Apple Silicon)
  • sdl2: stable 2.30.7 (from homebrew)
  • sdl2_image: stable 2.8.2 (from homebrew)

Issue:

vt100 binary compiles as expected, however crashes immediately at startup after briefly rendering the SDL window:

❯ ls
Makefile   ddt.c      keyboard.c nvr.c      render.c   sound.c    term.h     vt100      vt100.h
cpu.c      icon.jpg   main.c     pusart.c   rom.c      sys.c      video.c    vt100.dSYM
❯ ./vt100
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'nextEventMatchingMask should only be called from the Main Thread!'
*** First throw call stack:
(
	0   CoreFoundation                      0x000000018832e2ec __exceptionPreprocess + 176
	1   libobjc.A.dylib                     0x0000000187e12158 objc_exception_throw + 60
	2   AppKit                              0x000000018c30de2c -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 3096
	3   libSDL2-2.0.0.dylib                 0x0000000101190c14 Cocoa_PumpEventsUntilDate + 84
	4   libSDL2-2.0.0.dylib                 0x0000000101190dc4 Cocoa_PumpEvents + 56
	5   libSDL2-2.0.0.dylib                 0x0000000101108100 SDL_PumpEventsInternal + 64
	6   libSDL2-2.0.0.dylib                 0x0000000101108218 SDL_WaitEventTimeout_REAL + 88
	7   vt100                               0x0000000100aec02c refresh + 92
	8   vt100                               0x0000000100aeddd8 events + 52
	9   vt100                               0x0000000100ae73b8 cputhread + 64
	10  libSDL2-2.0.0.dylib                 0x000000010114875c SDL_RunThread + 48
	11  libSDL2-2.0.0.dylib                 0x00000001011a14d4 RunThread + 12
	12  libsystem_pthread.dylib             0x00000001881d9f94 _pthread_start + 136
	13  libsystem_pthread.dylib             0x00000001881d4d34 thread_start + 8
)
libc++abi: terminating due to uncaught exception of type NSException
[1]    60547 abort      ./vt100

If I comment out the following code, vt100 compiles as expected, and runs as expected with no crash:

161   if (SDL_PollEvent(NULL))
162     return;

Uncertain as to implication of commenting out this code, but it seems related to recent commit 0fe6abf.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions