Debug Tips
1) Start with the smallest failing scope
Section titled “1) Start with the smallest failing scope”When something breaks, isolate first:
- parser issue: run with invalid or edge-case
.cubfiles only - movement issue: test on a tiny closed map
- render issue: test with one texture family
- bonus issue: run
./cub3D_bonuson a minimal bonus map
Do not debug multiple subsystems at once.
2) Use staged validation commands
Section titled “2) Use staged validation commands”Run this sequence after each fix:
makemake bonusnorminette include srcs srcs_bonusmake testmake test_bonusThen run Valgrind only on the scenario that still fails.
3) Parser and validation debugging
Section titled “3) Parser and validation debugging”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.
4) Render debugging
Section titled “4) Render debugging”For wall deformation or wrong texture orientation:
- verify
perp_dist,draw_start, anddraw_end - inspect
wall_x,tex_x, andtex_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.
5) Collision and door debugging
Section titled “5) Collision and door debugging”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.
6) Sprite debugging
Section titled “6) Sprite debugging”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
7) HUD and minimap layout debugging
Section titled “7) HUD and minimap layout debugging”If UI elements overlap or drift:
- log panel anchors and computed widths
- verify the resolution-change path recomputes placements
- test at
F1,F2, andF3presets - keep HUD drawing at the end of the pipeline
8) Memory and shutdown debugging
Section titled “8) Memory and shutdown debugging”For leaks or double-free suspects:
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.
9) Fast regression prevention
Section titled “9) Fast regression prevention”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
10) Defense-oriented debugging habit
Section titled “10) Defense-oriented debugging habit”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.