Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
4 registered members (NewbieZorro, Grant, TipmyPip, AndrewAMD), 13,040 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Functions calling themselves #166561
11/08/07 21:41
11/08/07 21:41
Joined: Sep 2007
Posts: 14
X
xykynan Offline OP
Newbie
xykynan  Offline OP
Newbie
X

Joined: Sep 2007
Posts: 14
I created the following function and my program crashed. If it is not possible for functions to call themselves, what would a reasonable workaround be?

void move_tab (MENU_TAB* m, int a)
{
int j = 0;
int k = 0;
while (k <= m->pan_num)
{
m->panels[k]->pos_y += a;
k += 1;
}
k = 0;
while (k <= m->tex_num)
{
m->texts[k]->pos_y += a;
k += 1;
}
k = 0;
while (k <= m->tab_num)
{
move_tab (m->sub_tabs[0], a);
k += 1;
}
}

Thanks in advance!

Re: Functions calling themselves [Re: xykynan] #166562
11/08/07 22:30
11/08/07 22:30
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Functions calling themselves are called recursive functions. Might be of help for you when researching.

Anyhow, I think it's relating to how you pass your pointer to the function, maybe resulting in an infinite loop at the first function. Try without the loops but just a small counter (and global counter variable), does it still crash? Try to think of more testcases to get the piece of code causing the crash. Because recursive functions work fine, I did it.


Click and join the 3dgs irc community!
Room: #3dgs
Re: Functions calling themselves [Re: Joozey] #166563
11/08/07 22:33
11/08/07 22:33
Joined: Sep 2007
Posts: 14
X
xykynan Offline OP
Newbie
xykynan  Offline OP
Newbie
X

Joined: Sep 2007
Posts: 14
Thanks for the fast response!

I went through some tests and it turns out I had an empty pointer in one of my structs.
Sorry for the trouble.

Re: Functions calling themselves [Re: xykynan] #166564
11/08/07 22:34
11/08/07 22:34
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands



Click and join the 3dgs irc community!
Room: #3dgs
Re: Functions calling themselves [Re: Joozey] #166565
11/08/07 23:18
11/08/07 23:18
Joined: Dec 2000
Posts: 4,608
mk_1 Offline

Expert
mk_1  Offline

Expert

Joined: Dec 2000
Posts: 4,608
Afaik all recursive functions can be written as iterative functions (loop) and it's faster.


Follow me on twitter

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

Gamestudio download | 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