Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 840 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
function parameter and var pointer #431114
10/09/13 15:17
10/09/13 15:17
Joined: Aug 2002
Posts: 3,258
Mainz
oliver2s Offline OP
Expert
oliver2s  Offline OP
Expert

Joined: Aug 2002
Posts: 3,258
Mainz
It's me again...

I have following function to play a sound (it's called in while loop). This function plays a beginning sound, if the beginning sound is over, it plays the loop sound:

Code:
#define SND_MULTIPLIER 0.75
#define SND_RANGE 20
var SND_sfx_volume=100;

void ent_sound_start(ENTITY* ent_,SOUND* sndBegin,SOUND* sndLoop,SOUND* sndEnd,var* sndBeginHndl,var* sndLoopHndl,var* sndEndHndl)
{
	snd_stop(*sndEndHndl);
	if(sndBegin!=NULL
	&& !snd_playing(*sndBeginHndl)
	&& !snd_playing(*sndLoopHndl)
	&& *sndBeginHndl==0)
	{*sndBeginHndl=ent_playsound(ent_,sndBegin,SND_sfx_volume*SND_MULTIPLIER*SND_RANGE);}
	if(sndLoop!=NULL
	&& !snd_playing(*sndBeginHndl)
	&& !snd_playing(*sndLoopHndl))
	{*sndLoopHndl=ent_playloop(ent_,sndLoop,SND_sfx_volume*SND_MULTIPLIER*SND_RANGE);}
}



99% percent of the time I call this function, it works very well. But sometimes I get a random crash in the instruction "snd_playing(*sndLoopHndl)". I really don't know what's wrong. I guess it's something with pointers.

Last edited by oliver2s; 10/09/13 15:29.
Re: function parameter and var pointer [Re: oliver2s] #431115
10/09/13 15:29
10/09/13 15:29
Joined: Dec 2008
Posts: 1,218
Germany
Rackscha Offline
Serious User
Rackscha  Offline
Serious User

Joined: Dec 2008
Posts: 1,218
Germany
i don't even have a clue, why this compiles:
Code:
if(sndBegin!=NULL)
	&& !snd_playing(*sndBeginHndl)
	&& !snd_playing(*sndLoopHndl)
	&& *sndBeginHndl==0)
{}



there is a () missing around the whole statement!

Lite-C requires brackets around the whole condition in an if statement so this is usually not possible:
Code:
if (a == 0) && !B



and has to look like
Code:
if ((a == 0) && !B)



MY Website with news of my projects:
(for example my current
Muliplayer Bomberman,
GenesisPrecompiler for LiteC
and TileMaster, an easy to use Tile editor)
Sparetime-Development

Re: function parameter and var pointer [Re: Rackscha] #431116
10/09/13 15:30
10/09/13 15:30
Joined: Aug 2002
Posts: 3,258
Mainz
oliver2s Offline OP
Expert
oliver2s  Offline OP
Expert

Joined: Aug 2002
Posts: 3,258
Mainz
Sorry, it was just a copy & paste mistake from SED to the Forum. Edited my post.

Re: function parameter and var pointer [Re: oliver2s] #431117
10/09/13 16:12
10/09/13 16:12
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
Hehe, I hooked the ent_playsound and if I call the orig one Ill get exactly the same problem...
But even if I dont place ANY code in there wink

Re: function parameter and var pointer [Re: Ch40zzC0d3r] #431119
10/09/13 16:26
10/09/13 16:26
Joined: Aug 2002
Posts: 3,258
Mainz
oliver2s Offline OP
Expert
oliver2s  Offline OP
Expert

Joined: Aug 2002
Posts: 3,258
Mainz
As I mentioned the crashing instruction (only randomly) is this: "snd_playing(*sndLoopHndl)".

I found that out with the following code:
Code:
void ent_sound_start(ENTITY* ent_,SOUND* sndBegin,SOUND* sndLoop,SOUND* sndEnd,var* sndBeginHndl,var* sndLoopHndl,var* sndEndHndl)
{	
	diag("\n main_ent_sound_start.1");
	snd_stop(*sndEndHndl);
	diag("\n main_ent_sound_start.2");
	if(sndBegin!=NULL)
	{
		diag("\n main_ent_sound_start.2.1");
		if(!snd_playing(*sndBeginHndl))
		{
			diag("\n main_ent_sound_start.2.1.1");
			if(!snd_playing(*sndLoopHndl))
			{
				diag("\n main_ent_sound_start.2.1.1.1");
				if(*sndBeginHndl==0)
				{
					diag("\n main_ent_sound_start.2.1.1.1.1");
					*sndBeginHndl=ent_playsound(ent_,sndBegin,SND_sfx_volume*SND_MULTIPLIER*SND_RANGE);
					diag("\n main_ent_sound_start.2.1.1.1.2");
				}
				diag("\n main_ent_sound_start.2.1.1.2");
			}
			diag("\n main_ent_sound_start.2.1.2");
		}
		diag("\n main_ent_sound_start.2.2");
	}
	diag("\n main_ent_sound_start.3");
	if(sndLoop!=NULL)
	{
		diag("\n main_ent_sound_start.3.1");
		if(!snd_playing(*sndBeginHndl))
		{
			diag("\n main_ent_sound_start.3.1.1");
			if(!snd_playing(*sndLoopHndl))
			{
				diag("\n main_ent_sound_start.3.1.1.1");
				*sndLoopHndl=ent_playloop(ent_,sndLoop,SND_sfx_volume*SND_MULTIPLIER*SND_RANGE);
				diag("\n main_ent_sound_start.3.1.1.2");
			}
			diag("\n main_ent_sound_start.3.1.2");
		}
		diag("\n main_ent_sound_start.3.2");
	}
	diag("\n main_ent_sound_start.4");
}



If it crashs, "main_ent_sound_start.2.1.1" is the last entry in acklog.txt.

Re: function parameter and var pointer [Re: oliver2s] #431131
10/09/13 18:11
10/09/13 18:11
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Well if that crashes sndLoopHndl will most likely be a vagabonding pointer. You should inspect the code that calls this function and especially the value for the argument sndLoopHndl.

Is there a specific reasong why you pass a pointer to the handle instead of the handle itself?


Always learn from history, to be sure you make the same mistakes again...
Re: function parameter and var pointer [Re: Uhrwerk] #431132
10/09/13 18:18
10/09/13 18:18
Joined: Aug 2002
Posts: 3,258
Mainz
oliver2s Offline OP
Expert
oliver2s  Offline OP
Expert

Joined: Aug 2002
Posts: 3,258
Mainz
Originally Posted By: Uhrwerk
Is there a specific reasong why you pass a pointer to the handle instead of the handle itself?


Yes, because the handle have to get a new value. If I pass the handle instead of the pointer, I just get a local variable inside the function.

Re: function parameter and var pointer [Re: oliver2s] #431135
10/09/13 18:34
10/09/13 18:34
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
I don't know if the following quote affects you or not or even can be the reason for your crash (in any thinkable circumstance):

Quote:
Seien Sie vorsichtig wenn Sie beim Aufrufen anderer Funktionen nicht-statische, lokale Variablen als Argumente übergeben. Lokale Variablen existieren nämlich ausschließlich innerhalb der aufrufenden Funktion. Sobald diese per return oder wait() beendet wird, werden die Argumente ungültig.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: function parameter and var pointer [Re: Superku] #431136
10/09/13 18:46
10/09/13 18:46
Joined: Aug 2002
Posts: 3,258
Mainz
oliver2s Offline OP
Expert
oliver2s  Offline OP
Expert

Joined: Aug 2002
Posts: 3,258
Mainz
Shouldn't it crash every time then? It only crashs randomly. And the arguments I pass to the function are not local, they are variables from a global struct.

Re: function parameter and var pointer [Re: oliver2s] #431139
10/09/13 19:25
10/09/13 19:25
Joined: Jul 2013
Posts: 158
F
Feindbild Offline
Member
Feindbild  Offline
Member
F

Joined: Jul 2013
Posts: 158
try to give out/save information about the respective var then, since it must be something with the var that causes the crash. Debugging is no fun with Gamestudio.

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