Handmade Network»Forums
13 posts
Day 53: Wall Entities Won't Draw (Debugging Fried Brain)

Hi there,
Is there a protocol to asking for a code review? I've been following from home, typing out my own version of handmade hero one youtube video at a time. I don't have issues very often, I follow along and download Casey's source to compare with. At the end of day 53 however I seem to have lost control of my wall entities. I'd love for somebody to take a look and maybe they can spot something I'm missing? It seems like a lot to post my whole handmade.cpp here so I dumped it on pastebin. http://pastebin.com/U7N8mdZV

There are a few small differences in my code compared to Casey's (naming conventions mostly). I think the problem is either in the world generation code, or possibly with the SetCamera function. I've been going over it for two days now and I can't figure out what the issue is. Thanks in advance, brave souls!
Mārtiņš Možeiko
2380 posts / 2 projects
Day 53: Wall Entities Won't Draw (Debugging Fried Brain)
Edited by Mārtiņš Možeiko on
It would be much easier to debug, if we could run code under debugger. Debugging 1000 lines of code on pastebin is no fun...

Anyway, what was the last thing you changed that stopped drawing things you want? Can you revert to that version and apply changes incrementally to see which exact change breaks things? Then it should be pretty trivial to figure out what change breaks functionality.

And try to use debugger yourself:
1) put a breakpoint on DrawRectangle call in line 962, check if that gets executed at all? Does playerLeftTop and playerRightBot variables contain reasonable values?
2) if the DrawRectangle get's called, step over it to verify that pixels are really written to buffer where you expect (check the x and y).
3) but DrawRectangle doesn't get called, check if AddWall on line 709 gets executed (put a breakpoint and see if debugger stops). Does absTileX, absTileY, absTileZ contains reasonable values?
4) step over SetCamera function, check if ChangeEntityResidence on line 515 gets executed and is changing wall entity residence to high. If it doesn't, then why? Inspect local variables.

Debugging is about verifying all the assumptions you made. Question yourself about code you wrote and verify that it really does what you expect it to do.