Parent/child offset is double-counted at draw time #37

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

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

src/physics.c:192-197 writes a child's x as parent->x + vx -- an absolute
world coordinate. src/actor.c:273-279 then draws it at parent->x + obj->x,
while actor_visible three lines above tests the camera against the raw obj->x
as absolute.

Two readings of one field inside one function.

Confirmed by measurement: with the player at (280,146) and a (-14,+10) offset, the
guarded draw lands at (130,114) and the unguarded one at (410,260) -- off a
320x240 screen. Rendering both and hashing SDL_RenderReadPixels gives different
images.

Invisible only while the parent sits at the origin.

actor.h documents both readings, in two places, so the header cannot be used
to decide which one is intended. examples/jrpg works around it with a
renderfunc that nulls obj->parent for the duration of the draw.

Files: src/physics.c:192-197, src/actor.c:273-279, include/akgl/actor.h


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

**Source:** TODO.md, "Found while writing the manual" -> "Defects with no prior entry", item 2 (at bbb7b8f) `src/physics.c:192-197` writes a child's `x` as `parent->x + vx` -- an absolute world coordinate. `src/actor.c:273-279` then draws it at `parent->x + obj->x`, while `actor_visible` three lines above tests the camera against the raw `obj->x` as absolute. **Two readings of one field inside one function.** Confirmed by measurement: with the player at (280,146) and a (-14,+10) offset, the guarded draw lands at (130,114) and the unguarded one at (410,260) -- off a 320x240 screen. Rendering both and hashing `SDL_RenderReadPixels` gives different images. Invisible only while the parent sits at the origin. `actor.h` documents **both** readings, in two places, so the header cannot be used to decide which one is intended. `examples/jrpg` works around it with a `renderfunc` that nulls `obj->parent` for the duration of the draw. **Files:** `src/physics.c:192-197`, `src/actor.c:273-279`, `include/akgl/actor.h` --- Filed by Tachikoma (Claude Code, Opus 5, 1M context)
tachikoma added this to the 0.9.x milestone 2026-08-02 18:33:21 -04:00
tachikoma added the defectblast-radius:high labels 2026-08-02 18:33:21 -04:00
tachikoma added the status::grooming label 2026-08-02 18:49:19 -04:00
Sign in to join this conversation.