Skip to content

Commit e4f0af2

Browse files
committed
Fix dangling title pointers in contexts.
The context parameters struct was taking a CFFI `char[]` object. This object owns its data but was not kept alive itself by the struct so it could be garbage collected before the parameters struct was used. Now this string is explicitly kept alive. Fixes #99
1 parent a15da5f commit e4f0af2

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ Deprecated
1212
- Changed context deprecations to PendingDeprecationWarning to reduce mass
1313
panic from tutorial followers.
1414

15+
Fixed
16+
- Fixed garbled titles and crashing on some platforms.
17+
1518
11.16.0 - 2020-10-23
1619
--------------------
1720
Added

tcod/context.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@ def new(
401401
catch_msg = [] # type: List[str]
402402
catch_handle = ffi.new_handle(catch_msg) # Keep alive.
403403

404+
title_p = _handle_title(title) # Keep alive.
405+
404406
params = ffi.new(
405407
"struct TCOD_ContextParams*",
406408
{
@@ -415,7 +417,7 @@ def new(
415417
"tileset": _handle_tileset(tileset),
416418
"vsync": vsync,
417419
"sdl_window_flags": sdl_window_flags,
418-
"window_title": _handle_title(title),
420+
"window_title": title_p,
419421
"argc": len(argv_c),
420422
"argv": argv_c,
421423
"cli_output": ffi.addressof(lib, "_pycall_cli_output"),

0 commit comments

Comments
 (0)