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
1 registered members (TipmyPip), 18,449 guests, and 6 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
Vector pointer error #319861
04/18/10 12:14
04/18/10 12:14
Joined: Oct 2007
Posts: 306
Austria
A
Alan Offline OP
Senior Member
Alan  Offline OP
Senior Member
A

Joined: Oct 2007
Posts: 306
Austria
Hi,

I've been working on a medium-sized project lately (code split up in about 15 lite-c-files) when I suddenly realized that "snd_play(...)" caused a severe error during runtime:

"Invalid arguments in player_action"

Well, I opened it up and checked what might be wrong there. The SOUND* pointer was defined properly in the right place and snd_play() seemed to be okay, too. I used a workaround with

snd_play(snd_create("sound.wav"), 100, 0)

... but I wondered what might have caused this error, because with this workaround, everything worked fine (so the sound file wasn't broken or something like that).



Today, working on the same project again, I *accidentally* discovered the cause of this error. Have a look at the following - very short - example:

Code:
//test.c


void my_function(){
   VECTOR* my_vec = {x=0;y=0;z=0;}
   
   return;
}


SOUND* my_sound = "mySoundFile.wav";




function main(){
   level_load("");
   wait(2);
   snd_play(my_sound, 100, 0);
   
}




Nothing special. A function called "my_function" which doesn't do anything right now, a sound object definition and the main function. YET, this code WILL cause the "Invalid arguments in main" error every time it is run.
Now, what's the reason for that? The reason is the

VECTOR* my_vec = {x=0;y=0;z=0;}

... definition INSIDE "my_function". As soon as a VECTOR* object is defined inside a function ANYWHERE throughout the entire project, ALL other objects, including sounds, panels etc. will STOP WORKING! The compiler, however, doesn't say anything about local Vector declarations being wrong. Furthermore, locally defined vector objects themselves WORK fine! I never would have suspected them to be the source of the "Invalid arguments in main" error, I just discovered that by accident. The code above will stop causing the "Invalid arguments" error as soon as you comment out the local Vector declaration. I looked it up in the manual, I couldn't find any "warning" that you shouldn't create local vector objects, so please add that (since this error is ENORMOUSLY hard to detect).


Greets,



Alan

Re: Vector pointer error [Re: Alan] #319883
04/18/10 16:00
04/18/10 16:00
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
Why do you use a Vector POINTER?

use:
VECTOR my_vec;
vec_set(my_vec,nullvector);

Re: Vector pointer error [Re: Widi] #319887
04/18/10 16:26
04/18/10 16:26
Joined: Oct 2007
Posts: 306
Austria
A
Alan Offline OP
Senior Member
Alan  Offline OP
Senior Member
A

Joined: Oct 2007
Posts: 306
Austria
Originally Posted By: Widi
Why do you use a Vector POINTER?


Does that really matter? This thread is about this weird error after all...
Well, the reason is that I started with c-script a LONG time ago and read the "from c-script to lite-c" in the manual, there's an example of how to define a vector:

VECTOR* vSpeed = {x=10;y=20;z=30;}

Never thought of defining it without the "*". All of the predefined functions use vector POINTER parameters (vec_diff, vec_add and so on...), so I've always been working with pointers.


It might work by using a real vector instead of a pointer, but still that doesn't chang anything about the fact that using pointers (even accidentally) causes severe trouble and an error which is very hard to fix if you're not aware of the cause. There should at least be some kind of warning in the manual, don't you agree?

Last edited by Alan; 04/18/10 16:27.
Re: Vector pointer error [Re: Alan] #319986
04/19/10 11:22
04/19/10 11:22
Joined: Jul 2000
Posts: 28,024
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,024
Frankfurt
You're certainly right, the compiler should definitely give an error message here. You're using a global struct definition inside a function, which is wrong, but the compiler must indicate this. Otherwise you can look for ages for the reason of the problem.

It's too late for the current release candidate, but it will be fixed in the next update.

Re: Vector pointer error [Re: jcl] #320037
04/19/10 13:59
04/19/10 13:59
Joined: Oct 2007
Posts: 306
Austria
A
Alan Offline OP
Senior Member
Alan  Offline OP
Senior Member
A

Joined: Oct 2007
Posts: 306
Austria
@jcl: Nice to hear. It really wasn't easy to find out why my panels and sounds weren't working correctly and I'm glad that this error will be prevented to happen in the first place in the future.

Greets,


Alan


Moderated by  jcl, Nems, Spirit, Tobias 

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