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:
//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