Closed bonmas14 closed 4 months ago
That took me a while to find, but you are corrupting the heap because of a typo on this line:
world = alloc(get_heap_allocator(), sizeof(world));
I think you meant to do sizeof(world_t)
, because now you're just allocating 8 bytes but then as you create an entity and write to anything beyond 8 bytes of offset you start writing to unallocated memory.
Tip: if you do #define VERY_DEBUG 1
at the top of build.c, the memory allocator will do a lot more checks and catch heap corruption earlier and let you know when it sees it. Then you can spam "alloc" everywhere you suspect it might be happening to deduce which line causes the corruption.
This time it was a bit difficult to track down because the exact line that caused the corruption was entity->sprite = sprite_get(SPRITE_player);
because the struct member sprite
has an offset greater than 8, surpassing the 8 bytes of memory you allocated.
I also realize the error message that was outputted is a bit misleading, I'll improve that.
Thank you! I don't even understand how I didn't notice it right away. Now everything is working
Hello, i have problem when program just exits with error code when i do something with in allocated array. After some debug i've found oogabooga_run_tests() function, and after inserting it into my code that throws this error:
full output:
the problem i have with my game, is that when i dont move it works fine (bullets spawn correctly) but if before spawning any bullet (from startup) and move player, and try to spawn bullets 2 times, it drops error, to reproduce it just clone my game
steps to reproduce:
this is code that produces this error:
oogabooga_run_tests
higher thanentity_setup_player
it wont show any errorentry_mem_test.zip