akgl_game_update calls simulate through a NULL pointer -- segfault on frame one #36

Open
opened 2026-08-02 18:33:20 -04:00 by tachikoma · 0 comments
Collaborator

Source: TODO.md, "Found while writing the manual" -> "Defects with no prior entry", item 1 (at bbb7b8f)

akgl_game_update invokes akgl_physics->simulate(akgl_physics, NULL)
(src/game.c:792) with no NULL check, and akgl_default_physics is zeroed BSS --
all four method pointers are NULL.

A program that does not call akgl_physics_init_arcade/_null itself therefore
segfaults on its first frame
, measured as exit 139, rather than raising
AKERR_NULLPOINTER.

physics.h:8-9,195 tells the reader that akgl_game_init selects a backend from
a physics.engine property. It does not, and there is no such property, so a
caller who believes the header writes exactly the program that crashes.
This is
the worst first-contact experience in the library.

The line immediately after it, akgl_renderer->draw_world(akgl_renderer, NULL),
is unguarded in the same way and should be fixed in the same change.

The fix is a NULL check. Closing it touches src/game.c only. The header
claim is filed separately with the rest of the false header comments.

Files: src/game.c:792-793


Filed by Tachikoma (Claude Code, Opus 5, 1M context)

**Source:** TODO.md, "Found while writing the manual" -> "Defects with no prior entry", item 1 (at bbb7b8f) `akgl_game_update` invokes `akgl_physics->simulate(akgl_physics, NULL)` (`src/game.c:792`) with no NULL check, and `akgl_default_physics` is zeroed BSS -- all four method pointers are NULL. **A program that does not call `akgl_physics_init_arcade`/`_null` itself therefore segfaults on its first frame**, measured as exit 139, rather than raising `AKERR_NULLPOINTER`. `physics.h:8-9,195` tells the reader that `akgl_game_init` selects a backend from a `physics.engine` property. It does not, and there is no such property, so **a caller who believes the header writes exactly the program that crashes.** This is the worst first-contact experience in the library. The line immediately after it, `akgl_renderer->draw_world(akgl_renderer, NULL)`, is unguarded in the same way and should be fixed in the same change. **The fix is a NULL check.** Closing it touches `src/game.c` only. The header claim is filed separately with the rest of the false header comments. **Files:** `src/game.c:792-793` --- Filed by Tachikoma (Claude Code, Opus 5, 1M context)
tachikoma added this to the 0.9.x milestone 2026-08-02 18:33:20 -04:00
tachikoma added the defectblast-radius:high labels 2026-08-02 18:33:20 -04:00
tachikoma added the status::grooming label 2026-08-02 18:49:19 -04:00
Sign in to join this conversation.