I have this problem in two of my projects where applications just crash at random moments. And if I say random, I mean random. No connection to what is going on in the rest of the application.
I am making this demo-game for vsge2D: “Blue Moon”, a project I have long ago abandoned because started with too less programming skills. Now it’s supposed to help me add new features to vsge2D.
In my last post I wrote about entities shooting bullets. There was this point where I got that working, but the game tended to crash after a random number of bullets. (It was not a certain amount of time until the crash, I checked that as well.)
That’s a quite scary moment for me as a programmer who didn’t have to deal with such a strange problem for a long time now, because my usual debugging methods don’t apply for this sort of bug. But I didn’t give up, and found the problem:
First thing you have to know is that my graphics based on nodes is drawn recursively. Nodes have children which are drawn when the graphics engine draws their parent node.
Only the upper-most nodes are added to the graphics engine itself. (I wonder if it would be more efficient to add everything to one node in the engine??)
That means the parent pointer is NULL when the node is in the engine. In the entity copy-constructor the node is copied and entity determines whether it has a parent and so whether to add it to the engine or not. (I am getting the feeling my idea with the one node makes a lot more sens :P )
The problem in the end was that in the copy-constructor of the node, I had not set the pointer to the parent to NULL, so it got a random value from the RAM. Sometimes this went well, and well…. sometimes it didn’t and the application crashed.
(Okay, I think I’ll do that one node in engine thing… or does somebody have a better idea, maybe?)
This post was imported from tumblr