Error: FindGUIID: No matching GUI found

Started by Proskrito, Thu 12/06/2003 18:30:38

Previous topic - Next topic

Proskrito

Well, i got this error:

Error: FindGUIID: No matching GUI found: GUI may have been deleted.
The thing is, that it popped up afted editing neither no guis, nor gui-related functions.

After looking the possible cause, i found this:

i have this function:
function SetMode(string mode){

if (StrCaseComp("default",mode)==0) StrCopy(mode,defaultmode);

 if (StrCaseComp("walk to",mode) == 0) SetModeEx(mode,9);
 else if (StrCaseComp("look at",mode) == 0)  SetModeEx(mode,1);
 else if (StrCaseComp("use",mode) == 0)   SetModeInv(mode,0,1,"on");
 else if (StrCaseComp("give",mode) == 0)    SetModeInv(mode,1,0,"to");
 else if (StrCaseComp("talk to",mode) == 0) SetModeEx(mode,3);
 else if (StrCaseComp("pick up",mode) == 0)  SetModeEx(mode,5);
 else SetModeEx(mode,8);
}

and i have a global string variable called defaultmode.

Just before geting the error, the line in red was not working, because i never passed "default" as parameter, but when i did, i got the error. And since there is no GUI related stuff in there, nor in any of the functions called in thet function, i feel  ??? ???.
if i remove the red line, or dont pass "default" as parameter, the error dont happen.
EDIT: What is intended with the line in red is that SetMode(defaultmode) and SetMode("default"), do the same, but with the second option i get the error.
Any ideas??

Scorpiorus

Seems like you got what is called memory corruption error.
The problem of course with "default" thingy.
You see it's a string constant, right?
Then you pass it as parameter. ok.
But AGS do not pass a string itself but a reference to the string instead!
This means that changing the string inside the function would affect the original value ("default" string in this case).
So what we got is that mode variable points to the same memory area where "default" located.

Then if (StrCaseComp("default",mode)==0) StrCopy(mode,defaultmode); line.
What's wrong?
StrCopy(mode,defaultmode); <- that statement

as the mode points to a "default" constant we have here:

StrCopy("default",defaultmode)

that is bad, because defaultmode is a 200 chars string whereas "default" is a 7 chars string. So apart from first 7 symbols it overwrites 193 memory slots which may be related to to any another thing (GUIs for example).

I what to say that this kind of errors is one of the most dangerous as they can lead for totally unexpected results. It's a luck that error is found during the compiling process.


So to solve the problem just make another global string variable (probably default mode is it) to be sure you allocated 200 bytes (it's AGS string size) and pass it as SetMode(defaultmode);


-Cheers

Proskrito

oohhh i see...
i knew nothing about that
Thanks for the explanation scorpiorus!! :D

SMF spam blocked by CleanTalk