Game Engine Update - The Collision System (A funny bug)

in #game6 years ago

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.

2018-09-25_20-50-36.png

I finished the basic of the physics engine and the objects on my game are now colliding good :)

Sort:  

Congratulations @code-entropy! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

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:

SteemitBoard supports the SteemFest⁴ Travel Reimbursement Fund.
Vote for @Steemitboard as a witness to get one more award and increased upvotes!