Gamestudio Links
Zorro Links
Newest Posts
Lapsa's very own thread
by Lapsa. 06/26/24 12:45
Executing Trades on Next Bar Open
by Zheka. 06/20/24 14:26
A simple game ...
by VoroneTZ. 06/18/24 10:50
Face player all the time ...
by bbn1982. 06/18/24 10:25
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Lapsa), 1,339 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Mino, squik, AemStones, LucasJoshua, Baklazhan
19061 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 | 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