Skip to content

Debug Tips

When something breaks, isolate first:

  • parser issue: run with invalid or edge-case .cub files only
  • movement issue: test on a tiny closed map
  • render issue: test with one texture family
  • bonus issue: run ./cub3D_bonus on a minimal bonus map

Do not debug multiple subsystems at once.

Run this sequence after each fix:

Terminal window
make
make bonus
norminette include srcs srcs_bonus
make test
make test_bonus

Then run Valgrind only on the scenario that still fails.

If startup fails before the window opens:

  • print which parser step fails (headers, map_start, validate_map)
  • test with a known-good map first, then mutate one field at a time
  • compare the failure against the expected rejection category

Typical categories:

  • missing or duplicate header
  • bad texture path
  • bad RGB
  • invalid map symbol
  • enclosure leak

This avoids chasing the wrong assumption.

For wall deformation or wrong texture orientation:

  • verify perp_dist, draw_start, and draw_end
  • inspect wall_x, tex_x, and tex_y
  • verify face-flip conditions for tex_x
  • temporarily force one wall texture to isolate selection vs mapping bugs

If visuals look sheared, suspect tex_y stepping or initial texture offset first.

If the player clips through geometry or gets blocked unexpectedly:

  • log attempted (dx, dy) and final applied position
  • test axis-by-axis movement near corners
  • print door tile, state, and progress during interaction
  • compare collision queries against raycast visibility for the same tile

Movement and rendering must agree on door passability.

If sprites render in the wrong order or through walls:

  • confirm zbuf[x] is written during raycast
  • verify sprite sort uses descending distance
  • inspect projection depth and screen bounds (x0, x1, y0, y1)
  • check opaque filtering in the texel draw path

If UI elements overlap or drift:

  • log panel anchors and computed widths
  • verify the resolution-change path recomputes placements
  • test at F1, F2, and F3 presets
  • keep HUD drawing at the end of the pipeline

For leaks or double-free suspects:

Terminal window
valgrind --leak-check=full --track-fds=yes ./cub3D <map.cub>

Verify cleanup order:

  • images
  • window
  • display
  • pointers and maps

On transfer or reload paths, ensure moved ownership is nulled before freeing temporary contexts.

After each meaningful fix:

  • reproduce the bug on a minimal map
  • apply a focused patch
  • rerun the same scenario
  • run the full smoke sequence (make test, make test_bonus)
  • commit only when the fix is both effective and non-regressive

Keep a short log of known and fixed issues:

  • symptom
  • root cause
  • file or function changed
  • how the fix was verified

This improves both technical quality and defense clarity.