Random Crashes? Possible Solution…

This is an old ar­ti­cle from 2012. I was a kid. I learned a lot since then, so please do think twice when tak­ing ad­vice from me as a kid.

I have this prob­lem in two of my projects where ap­pli­ca­tions just crash at ran­dom mo­ments. And if I say ran­dom, I mean ran­dom. No con­nec­tion to what is go­ing on in the rest of the ap­pli­ca­tion.

I am mak­ing this de­mo-game for vs­ge2D: “Blue Moon”, a project I have long ago aban­doned be­cause start­ed with too less pro­gram­ming skills. Now it’s sup­posed to help me add new fea­tures to vs­ge2D.

In my last post I wrote about en­ti­ties shoot­ing bul­lets. There was this point where I got that work­ing, but the game tend­ed to crash af­ter a ran­dom num­ber of bul­lets. (It was not a cer­tain amount of time un­til the crash, I checked that as well.)

That’s a quite scary mo­ment for me as a pro­gram­mer who didn’t have to deal with such a strange prob­lem for a long time now, be­cause my usu­al de­bug­ging meth­ods don’t ap­ply for this sort of bug. But I didn’t give up, and found the prob­lem:

First thing you have to know is that my graph­ics based on nodes is drawn re­cur­sive­ly. Nodes have chil­dren which are drawn when the graph­ics en­gine draws their par­ent node.

On­ly the up­per-most nodes are added to the graph­ics en­gine it­self. (I won­der if it would be more ef­fi­cient to add ev­ery­thing to one node in the en­gine??)

That means the par­ent point­er is NULL when the node is in the en­gine. In the en­ti­ty copy-con­struc­tor the node is copied and en­ti­ty de­ter­mines whether it has a par­ent and so whether to add it to the en­gine or not. (I am get­ting the feel­ing my idea with the one node makes a lot more sens :P )

The prob­lem in the end was that in the copy-con­struc­tor of the node, I had not set the point­er to the par­ent to NULL, so it got a ran­dom val­ue from the RAM. Some­times this went well, and well…. some­times it didn’t and the ap­pli­ca­tion crashed.

(Okay, I think I’ll do that one node in en­gine thing… or does some­body have a bet­ter idea, maybe?)

This post was im­port­ed from tum­blr


Archived blog posts from squareys.tum­blr.com.