Page 1 of 1

[0.17.60] Checking equality with LuaGameScript crashes the game

Posted: Thu Aug 01, 2019 12:36 am
by raiguard
Hello. The following code will crash the game:

Code: Select all

script.on_init(function(e)
    log('Crashing game by comparing with LuaGameScript:')
    game.print(game.forces[1] == game)
    log('If you\'re seeing this, the game didn\'t crash!')
end)
If you run this in a mod, the game will crash. By looking at the crash report it seems that checking equality with LuaGameScript will crash, whether you're using == or ~=.

Thanks for your time!

Re: [0.17.60] Checking equality with LuaGameScript crashes the game

Posted: Thu Aug 01, 2019 2:16 am
by Rseding91
Thanks for the report. It's now fixed for the next version of 0.17.

I'm not sure why you would ever *want* to check if game is equal to anything since it will always report false now but at least it won't crash.

Re: [0.17.60] Checking equality with LuaGameScript crashes the game

Posted: Thu Aug 01, 2019 2:46 am
by raiguard
My usecase was that I had a generalized function that could have one of a LuaPlayer, LuaForce, LuaSurface, or LuaGameScript as one of the arguments. For the first three, I wanted to get the index of the object. However, game has no index (and trying to do game.index returns an error instead of nil), so I wanted to have special logic if the function was passed game.

I already worked around it, so it's no biggie. Thanks for fixing the bug!

Edit: I would advise adding a "trying to check equality with this object will always return false" warning in the docs somewhere.