Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 20:05
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 1,438 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
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 Offline OP
Expert
Germanunkol  Offline 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: Germanunkol] #376889
07/07/11 12:59
07/07/11 12:59
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
are you using malloc or realloc on pointer you've defined before it?

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 Offline OP
Expert
Germanunkol  Offline 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: Germanunkol] #376891
07/07/11 13:03
07/07/11 13:03
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
just thinking you could be clearing the data using either of those if you're clearing the incorrect size, are you able to remove those from the code without too much trouble and see if you still get the crash

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 Offline OP
Expert
Germanunkol  Offline 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 Offline OP
Expert
Germanunkol  Offline 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: Germanunkol] #376982
07/08/11 12:34
07/08/11 12:34
Joined: May 2007
Posts: 2,043
Germany
Lukas Offline

Programmer
Lukas  Offline

Programmer

Joined: May 2007
Posts: 2,043
Germany
Maybe you have an array you access with an invalid index? Did you define an array right before you defined your text? If so, it's most probably that array. Else, it could still be any other array.

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 Offline OP
Expert
Germanunkol  Offline 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: Germanunkol] #376997
07/08/11 18:45
07/08/11 18:45
Joined: May 2007
Posts: 2,043
Germany
Lukas Offline

Programmer
Lukas  Offline

Programmer

Joined: May 2007
Posts: 2,043
Germany
Well, for me wrong array indicies or invalid pointers != NULL often don't crash and instead change some random thing in Lite-C.
If you don't do anything to your pointer in the script, then is must be something where you accidentally access something random and that thing in this case always seems to be your text.

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 Offline OP
Expert
Germanunkol  Offline 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
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1