• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Wierd Error with Expression Macros

T

tomsaram

Guest
Hi,

I am having this error that I cannot make sense of:
Final Compile...Error : gml_Script_GameInitialize(0) : Fatal Error while compiling - bailing details below
System.NullReferenceException: Object reference not set to an instance of an object.
at ...ctor( _value)
at ...ctor( _tok)
at ..( )
at ..( )
at ..( )
at ..( )
at GMAssetCompiler.GML2VM.( , )

(And there are weird boxes in those brackets, like when you try to play a Japanese game on a machine that does not have the language installed)

I somehow narrowed the error to this line:
Code:
global.DTBS_NUMBER[3] = DTBS_OTHER_NUM - DTBS_ENEMY_NUM;
Or more specifically, the use of macro DTBS_OTHER_NUM. The macro is defined as follows:
Code:
...
DTBS_OTHER_NUM    |    (DTBS_ENEMY_NUM+20)
DTBS_ENEMY_NUM    |    (DTBS_BOSS_NUM+5)
DTBS_BOSS_NUM     |    (DTBS_EVENT_NUM+1)
DTBS_EVENT_NUM    |    2
....
The weird thing is that DTBS_ENEMY_NUM and DTBS_BOSS_NUM are completely fine, although they are defined in the exact same way as DTBS_OTHER_NUM. Something seems to be special with DTBS_OTHER_NUM, and I don't know what.

The following things seems to fix the error:
1. Avoid using DTBS_OTHER_NUM at all.
2. Define DTBS_OTHER_NUM as the literal 28.
3. Define DTBS_OTHER_NUM as the expression (DTBS_BOSS_NUM+25). (I found this curious one by mistake)

Does anyone have a clue on why this is? I know I can fix this simply by defining my macros as literals, but I am really curious.

Thanks.

P.S. Now that we are on the topic of macros, Is there a way to define a macro as an array? This is kind of what I wanted to do with global.DTBS_NUMBER.

Edit: jo-thijs pointed out that the expressions need brackets. I added the brackets but it seems to be irrelevant to the compiler error.
 
Last edited by a moderator:

jo-thijs

Member
Hi,

I am having this error that I cannot make sense of:
Final Compile...Error : gml_Script_GameInitialize(0) : Fatal Error while compiling - bailing details below
System.NullReferenceException: Object reference not set to an instance of an object.
at ...ctor( _value)
at ...ctor( _tok)
at ..( )
at ..( )
at ..( )
at ..( )
at GMAssetCompiler.GML2VM.( , )

(And there are weird boxes in those brackets, like when you try to play a Japanese game on a machine that does not have the language installed)

I somehow narrowed the error to this line:
Code:
global.DTBS_NUMBER[3] = DTBS_OTHER_NUM - DTBS_ENEMY_NUM;
Or more specifically, the use of macro DTBS_OTHER_NUM. The macro is defined as follows:
...
DTBS_OTHER_NUM | DTBS_ENEMY_NUM+20
DTBS_ENEMY_NUM | DTBS_BOSS_NUM+5
DTBS_BOSS_NUM | DTBS_EVENT_NUM+1
DTBS_EVENT_NUM | 2
....

The weird thing is that DTBS_ENEMY_NUM and DTBS_BOSS_NUM are completely fine, although they are defined in the exact same way as DTBS_OTHER_NUM. Something seems to be special with DTBS_OTHER_NUM, and I don't know what.

The following things seems to fix the error:
1. Avoid using DTBS_OTHER_NUM at all.
2. Define DTBS_OTHER_NUM as the literal 28.
3. Define DTBS_OTHER_NUM as the expression DTBS_BOSS_NUM+25. (I found this curious one by mistake)

Does anyone have a clue on why this is? I know I can fix this simply by defining my macros as literals, but I am really curious.

Thanks.

P.S. Now that we are on the topic of macros, Is there a way to define a macro as an array? This is kind of what I wanted to do with global.DTBS_NUMBER.
I don't know what that error means exactly.

I do spot a mistake in how you're using macros however.
Macros aren't constants.
They're not a variable with ssome value.
They're actual pieces of code that get copied where you use them.

You do this:
Code:
global.DTBS_NUMBER[3] = DTBS_OTHER_NUM - DTBS_ENEMY_NUM;
with macro definitions:
Code:
DTBS_OTHER_NUM    |    DTBS_ENEMY_NUM+20
DTBS_ENEMY_NUM    |    DTBS_BOSS_NUM+5
DTBS_BOSS_NUM     |    DTBS_EVENT_NUM+1
DTBS_EVENT_NUM    |    2
That line of code will be translated to:
Code:
global.DTBS_NUMBER[3] = 2+1+5+20 - 2+1+5;
This is equivalent to:
Code:
global.DTBS_NUMBER[3] = 32;
instead of the intended:
Code:
global.DTBS_NUMBER[3] = 20;
To fix this, you should put all of your macro bodies inside parentheses, like so:
Code:
DTBS_OTHER_NUM    |    (DTBS_ENEMY_NUM+20)
DTBS_ENEMY_NUM    |    (DTBS_BOSS_NUM+5)
DTBS_BOSS_NUM     |    (DTBS_EVENT_NUM+1)
DTBS_EVENT_NUM    |    2
I don't see how this would result in a compile time failure however.
Maybe some optimization already tries to use the value stored in the array?

What target are you compiling for?
What is the definition of DTBS_NUMBER?

Also, as to your question of using macros for arrays.
Not in the way you're trying to use it in your example.
Macros don't provide any storage, they just change the code you wrote in a preprocessor step.
As a result, you cannot store values in them.
 
T

tomsaram

Guest
I do spot a mistake in how you're using macros however.
Macros aren't constants.
They're not a variable with some value.
They're actual pieces of code that get copied where you use them.
I did a little test and you are right about how brackets are needed for macro. Here is my updated macro definition:
Code:
...
DTBS_OTHER_NUM    |    (DTBS_ENEMY_NUM+20)
DTBS_ENEMY_NUM    |    (DTBS_BOSS_NUM+5)
DTBS_BOSS_NUM     |    (DTBS_EVENT_NUM+1)
DTBS_EVENT_NUM    |    2
...
This however does not remove the problem I am getting. Here is the updated full definition of global.DTBS_NUMBER:
Code:
...
// global.DTBS_NUMBER[3] = DTBS_OTHER_NUM - DTBS_ENEMY_NUM; //does not compile
global.DTBS_NUMBER[3] = 28 - DTBS_ENEMY_NUM;
global.DTBS_NUMBER[2] = DTBS_ENEMY_NUM - DTBS_BOSS_NUM;
global.DTBS_NUMBER[1] = DTBS_BOSS_NUM - DTBS_EVENT_NUM;
global.DTBS_NUMBER[0] = DTBS_EVENT_NUM;
...
I am compiling for Windows.
 

jo-thijs

Member
I did a little test and you are right about how brackets are needed for macro. Here is my updated macro definition:
Code:
...
DTBS_OTHER_NUM    |    (DTBS_ENEMY_NUM+20)
DTBS_ENEMY_NUM    |    (DTBS_BOSS_NUM+5)
DTBS_BOSS_NUM     |    (DTBS_EVENT_NUM+1)
DTBS_EVENT_NUM    |    2
...
This however does not remove the problem I am getting. Here is the updated full definition of global.DTBS_NUMBER:
Code:
...
// global.DTBS_NUMBER[3] = DTBS_OTHER_NUM - DTBS_ENEMY_NUM; //does not compile
global.DTBS_NUMBER[3] = 28 - DTBS_ENEMY_NUM;
global.DTBS_NUMBER[2] = DTBS_ENEMY_NUM - DTBS_BOSS_NUM;
global.DTBS_NUMBER[1] = DTBS_BOSS_NUM - DTBS_EVENT_NUM;
global.DTBS_NUMBER[0] = DTBS_EVENT_NUM;
...
I am compiling for Windows.
TBS_NUMBER is not a macro?

Have you already tried cleaning your cache?
If you import your resources into a new project, do you still have the same issues?
 

jo-thijs

Member
It is just a global.variable.

I tried cleaning the cache. Same error.
If you don't mind, you could upload the GMZ file (file > export project) of your project somewhere (mediafire, dropbox, onedrive, ...) and share the link.
That would make me find the issue faster.

Otherwise I don't have a clue right now and I would just ask for more information.
For example, is there any other relevant code?
Is there any strange behavior when you comment out the problem line?
Can you figure anything out when using break points and the debugger while the problem line
Do you have any clue what the script GameInitialize may be referring to?
 
Top