Skip to content

Commit f166816

Browse files
committed
Skip checking events when the SDL event subsystem is offline.
Fixes a known access violation.
1 parent 100bccc commit f166816

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ This project adheres to [Semantic Versioning](https://semver.org/) since version
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
- Fixed access violation when events are polled before SDL is initialized.
12+
913
## [16.2.2] - 2024-01-16
1014

1115
### Fixed

tcod/event.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292

9393
import tcod.event_constants
9494
import tcod.sdl.joystick
95+
import tcod.sdl.sys
9596
from tcod.cffi import ffi, lib
9697
from tcod.event_constants import * # noqa: F403
9798
from tcod.event_constants import KMOD_ALT, KMOD_CTRL, KMOD_GUI, KMOD_SHIFT
@@ -1196,6 +1197,13 @@ def get() -> Iterator[Any]:
11961197
It is also safe to call this function inside of a loop that is already handling events
11971198
(the event iterator is reentrant.)
11981199
"""
1200+
if not lib.SDL_WasInit(tcod.sdl.sys.Subsystem.EVENTS):
1201+
warnings.warn(
1202+
"Events polled before SDL was initialized.",
1203+
RuntimeWarning,
1204+
stacklevel=1,
1205+
)
1206+
return
11991207
sdl_event = ffi.new("SDL_Event*")
12001208
while lib.SDL_PollEvent(sdl_event):
12011209
if sdl_event.type in _SDL_TO_CLASS_TABLE:

0 commit comments

Comments
 (0)