Game Engine Update - The Collision System (A funny bug)
Two days ago I was working on the collision system of my physics engine, and I lost two hours searching for a bug with the collide()
function because the game crashed just when an object collide with another making a memory leak with a pointer.
After reading the function many times and printing log for everything I used valgrind
. A tool that can help to debug memory leaks. I really recommend it to debug C/C++
code it is really helpful.
While reading the backtrace I found the struct that was making the memory leak:
struct Manifold {
...
Vec2 collision_points[0];
...
};
I declared an 0 size array... So when the collide function tried to add a value to any of the indexes the memory leak occurred on the manifold pointer.
A really fun mistake, I laugh and said to myself how stupid and small it was and the big troubles that comes with it ja, ja, ja.
After that the same experience occurred when I was using +
instead -
and it made the objects pass through walls on continuous collisions.
I finished the basic of the physics engine and the objects on my game are now colliding good :)
Congratulations @code-entropy! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Do not miss the last post from @steemitboard:
Vote for @Steemitboard as a witness to get one more award and increased upvotes!