Adventure Game Studio | Forums

AGS Development => Editor Development => Topic started by: Monsieur OUXX on Tue 07/08/2018 23:50:03

Title: Compiler bug? non-declared variable accepted by compiler but crashes game at run
Post by: Monsieur OUXX on Tue 07/08/2018 23:50:03
Hello,

- Download the following game project : https://drive.google.com/open?id=1CS_A6xhadFua2dKSAtmsU1oO3aWhfcDQ
- Open it with the (slightly outdated) 3.4.1 - patch 2 (that's 3.4.1.13)
- compile the game. The compiler raises no error
- put a breakpoint on lines 1685 and 1715 in VerbGui.asc.
- Run the game.
- single-click anywhere in the room (once). the character starts walking there. Then double-click on the door to the holodeck (south of the screen). This triggers a breakpoint on line 1685.
- Press F5. You never reach line 1715.

This proves that the game crashes on line 1685.

Now, for the strange part : location_id is declared nowhere.
There used to be a line "int location_id;" in this file, but the variable has been moved to a struct and you'd need to do verbsData.location_id to access that value. Proof : just above the line that causes the crash, add "location_id = 0;". The compiler will reject it.
This seems to prove that the compiler lets through this non-existing variable in some specific conditions.

Here is the scenario that I suspect :
1. the compiler lets through a non-existing variable for some absurd synctactical reason (maybe because it's in brackets : hotspot[location_id] )
2. then at runtime, the mistake is still not caught when resolving hotspot[location_id] --> that returns a bullshit pointer
3. this faulty resolution is passed as some sort of faulty this* parameter to RunInteraction(this*, ...).
4. the faulty this* makes the game crash when RunInteraction tries to propagate it as a on_mouse_click.
(but that's just my two cents. I'm just trying to understand how a non-existing variable is caught only at runtime and in some events-related built-in function)

Could it also be some sort of compiler cache issue? (I mean : does the fact that there was an int location_id previously in the code potentially play a role?)
Title: Re: Compiler bug? non-declared variable accepted by compiler but crashes game at run
Post by: Monsieur OUXX on Wed 15/08/2018 19:53:32
CW did you see that?
Title: Re: Compiler bug? non-declared variable accepted by compiler but crashes game at run
Post by: Crimson Wizard on Wed 15/08/2018 21:16:15
Yes, it compiles when it should not compile, and it crashes.
There is no such thing as a script cache; script desync issues happen with rooms sometimes when you are using rooms compiled with some older version of global script, but it does not look like that case, besides I did several "rebuild all files" to be sure.

I would not make assumptions of all the process, but so far this looks like a compiler bug. If it had a parsing mistake and produced wrong byte code, then engine got into trouble following it.

Best thing we may do is to find accurate conditions under which this bug occurs. If we have a smallest possible code snippet that causes same bug, then it will be much easier to find out what is going on.

EDIT: this code is enough to cause error:
Code (ags) Select

struct MyStruct
{
    int var;
    import void Func();
};

void d()
{
    MyStruct s;
    MyStruct arrs[10];
    if (s.var == 1) arrs[var].Func(); // this must throw compiler error but does not
    if (s.var == 1) arrs[var].var = 1; // this correctly throws compiler error
}