Handmade Hero»Forums»Code
Miguel Lechón
78 posts / 2 projects
Insignificant bug in platform code
Hi,

This thing maybe doesn't even deserve being called "bug". It barely meets the definition of the word. Anyways, here's how you trigger it:
- Launch the game
- Hit 'L' before the window comes up
This tells the platform layer to start a recording before the game has had the chance to set up its game_state properly. Only a bunch of zeros are written to disk.
- Wait for the game to load
The game code then initializes game_state and sets the isInitialized flag inside the game_memory struct to true.
- Hit 'L' again.
The platform layer overwrites the game memory block with the zeros it stored previously. The game still sees the IsInitialized flag as true and happily dereferences 0x00000000.

I see two possible fixes:
- Checking if IsInitialized is set before starting recording a game loop
- Not hitting 'L' for 200 ms while the game starts.
Casey Muratori
801 posts / 1 project
Casey Muratori is a programmer at Molly Rocket on the game 1935 and is the host of the educational programming series Handmade Hero.
Insignificant bug in platform code
Actually this is a pretty good point, because it clears up a distinction we were having that we shouldn't have had. If you remember, I was vacillating at the beginning between having the IsInitialized vs. just having the game check to see if the first DWORD of the memory was 0 or not. Well, now we have a very good reason why the latter should be preferred! It would "just work" in this scenario, whereas the IsInitialized case requires us to do a bunch of other work.

So, although it's not a bug we care about in terms of shipping the game, I do think it's a bug we care about because it clears up an architectural decision that could have gone either way, and now we have a good piece of data to decide on one of the ways.

- Casey