Jim R. Didriksen
63 posts
Day 085 how did that code build ?
Edited by Jim R. Didriksen on
after a little over an hour of trying to find what I misspelled or something I find that the code written in the video that builds won't build on my computer

 1 2 3 4 5 6 7 8 9  // NOTE(casey): Transient initialization Assert(sizeof(transient_state) <= Memory->TransientStorageSize); transient_state *TranState = (transient_state *)Memory->TransientStorage; if(!TranState->IsInitialized) { InitializeArena(&TranState->TranArena, Memory->TransientStorageSize - sizeof(transient_state), (uint8 *)Memory->TransientStorageSize + sizeof(transient_state)); 

This is in the code and build fine in the video but I get access violations as the TranState pointer fetched is garbage. because it should be (or at least that is what worked here)

 1 2 3 4 5 6 7 8 9  // NOTE(casey): Transient initialization Assert(sizeof(transient_state) <= Memory->TransientStorageSize); transient_state *TranState = (transient_state *)Memory->TransientStorage; if(!TranState->IsInitialized) { InitializeArena(&TranState->TranArena, Memory->TransientStorageSize - sizeof(transient_state), (uint8 *)Memory->TransientStorage + sizeof(transient_state)); 

the 3rd argument being how far we have eating our way into the TransientArena/TranState->TranArena

I did try to build the official day 85 code and it gives the same error as the code I have written along with.

Am I misunderstanding or is there some weird difference in our setups since it built on stream but not here?

Edit: I just want to know to save possible bug fixing in the future.
Bryan Taylor
55 posts
Day 085 how did that code build ?
Casey addresses this at the start of day 87.

Basically: it's a typo. He's casting the integer size of the transient storage to a pointer. By chance, that integer -- interpreted as an address -- happened to point to valid memory when Casey ran it. A segfault is the expected behavior here, but when you're poking at random places on the heap there are no guarantees. (Even when it "works", you're by definition trashing memory someone else is using -- one of you is going to get garbage results, which may or may not crash somewhere else down the line.)
Jim R. Didriksen
63 posts
Day 085 how did that code build ?
Ah thanks.