Skip to content

Commit 2180a75

Browse files
committed
Fix _sdl_event_watcher cdef
Type did not match the function def demanded by SDL for event watching and was crashing Add tests to ensure that this function works
1 parent 1c97375 commit 2180a75

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
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+
- `tcod.event.add_watch` was crashing due to a cdef type mismatch.
12+
913
## [19.6.0] - 2025-10-20
1014

1115
### Added

build_sdl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def get_emscripten_include_dir() -> Path:
311311
// SDL to Python log function.
312312
void _sdl_log_output_function(void *userdata, int category, SDL_LogPriority priority, const char *message);
313313
// Generic event watcher callback.
314-
int _sdl_event_watcher(void* userdata, SDL_Event* event);
314+
bool _sdl_event_watcher(void* userdata, SDL_Event* event);
315315
}
316316
"""
317317

tests/test_tcod.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,16 @@ def test_context(uses_window: None) -> None: # noqa: ARG001
204204
context.pixel_to_subtile(0, 0)
205205
with pytest.raises(RuntimeError, match=r".*context has been closed"):
206206
context.present(console)
207+
208+
209+
def test_event_watch() -> None:
210+
def handle_events(_event: tcod.event.Event) -> None:
211+
pass
212+
213+
tcod.event.add_watch(handle_events)
214+
with pytest.warns(RuntimeWarning, match=r"nothing was added"):
215+
tcod.event.add_watch(handle_events)
216+
217+
tcod.event.remove_watch(handle_events)
218+
with pytest.warns(RuntimeWarning, match=r"nothing was removed"):
219+
tcod.event.remove_watch(handle_events)

0 commit comments

Comments
 (0)