Author Topic: Compiler bug? non-declared variable accepted by compiler but crashes game at run  (Read 460 times)

Monsieur OUXX

  • Mittens Half Initiate
    • I can help with proof reading
    • I can help with translating
    • I can help with voice acting

- 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
- 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?)

Monsieur OUXX

  • Mittens Half Initiate
    • I can help with proof reading
    • I can help with translating
    • I can help with voice acting
CW did you see that?

Crimson Wizard

  • Local Moderator
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    • Lifetime Achievement Award Winner
    • Crimson Wizard worked on a game that won an AGS Award!
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
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: Adventure Game Studio
  1. struct MyStruct
  2. {
  3.     int var;
  4.     import void Func();
  5. };
  7. void d()
  8. {
  9.     MyStruct s;
  10.     MyStruct arrs[10];
  11.     if (s.var == 1) arrs[var].Func(); // this must throw compiler error but does not
  12.     if (s.var == 1) arrs[var].var = 1; // this correctly throws compiler error
  13. }
« Last Edit: 15 Aug 2018, 21:28 by Crimson Wizard »