0 registered members (),
1,438
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
How to find out what function deletes my object
#376888
07/07/11 12:54
07/07/11 12:54
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
OP
Expert
|
OP
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
I have a text object defined like this:
TEXT* ss_ledgendDeathsText = { strings = 1; string("suicides"); font = ss_smallFont; layer = 62; }
At some point, I suddenly get a crash, and I found out that it is due to "ledgendDeathsText" being NULL.
I checked, I never remove ledgendDeathsText anywhere, so why could it be NULL? Even if another function would remove the object, would not the pointer still point to the same location? Also, the text is still displayed on screen... so I suspect only the pointer gets set to 0. But how can that be, when the only things I ever do with ledgendDeathsText are the following (these lines are all over my code, not in one place):
ss_players[playerIndex].deathsTxt.pos_x = ss_ledgendDeathsText.pos_x; ss_ledgendDeathsText.pos_x = ss_ledgendScoreText.pos_x - 30 - str_width((ss_ledgendDeathsText.pstring)[0],ss_ledgendDeathsText.font); ss_ledgendDeathsText.pos_y = ss_ledgendPlayerText.pos_y; ss_ledgendKillsText.pos_x = ss_ledgendDeathsText.pos_x - 30 - str_width((ss_ledgendKillsText.pstring)[0],ss_ledgendKillsText.font);
set(ss_ledgendDeathsText,SHOW); reset(ss_ledgendDeathsText,SHOW);
As you can see, I never reassign ss_ledgendDeahsText anywhere in the code, neither do I create any pointer pointing at the ss_ledgendDeahsText pointer, so how could it EVER be 0?!
Last edited by Germanunkol; 07/07/11 12:55.
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
Re: How to find out what function deletes my object
[Re: MrGuest]
#376890
07/07/11 13:00
07/07/11 13:00
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
OP
Expert
|
OP
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
I use sys_malloc and sys_free quite a few times in my code, yes. Why?
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
Re: How to find out what function deletes my object
[Re: MrGuest]
#376892
07/07/11 13:05
07/07/11 13:05
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
OP
Expert
|
OP
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
well I only ever sys_free like this: sys_free(point);
So it clears exactly the size of "point", right? No more, no less. Also, the pointer is set to NULL, the object behind the pointer is not overwritten.
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
Re: How to find out what function deletes my object
[Re: Germanunkol]
#376905
07/07/11 16:13
07/07/11 16:13
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
OP
Expert
|
OP
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
It looks like I've found a (disgusting) workaround.
Instead of keeping the one text object for the entire game, I now recreate it every time the function is called, and delete it at the end, so it doesn't matter if something happens with the pointer inbetween.
For now I can just hope it doesn't set some other random pointer to NULL...
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
Re: How to find out what function deletes my object
[Re: Lukas]
#376996
07/08/11 18:39
07/08/11 18:39
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
OP
Expert
|
OP
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
Nope, before I define the text, another text is defined, which is always used in the same context (i.e. whenever text1 is visible, so is text2).
Also, wrong array indecies should result in a crash, not in setting a pointer to NULL...?
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
Re: How to find out what function deletes my object
[Re: Lukas]
#376999
07/08/11 19:20
07/08/11 19:20
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
OP
Expert
|
OP
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
This does sound reasonable. Any hints on how to find such a thing?
If I start looking through all arrays in my script, I'll probably still be looking in a month... I could add logging functions before all array accesses, to log the indices, but that sounds expensive...
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
|