[0.17.60] Checking equality with LuaGameScript crashes the game

This subforum contains all the issues which we already resolved.
Post Reply
User avatar
raiguard
Factorio Staff
Factorio Staff
Posts: 451
Joined: Wed Dec 13, 2017 8:29 pm
Contact:

[0.17.60] Checking equality with LuaGameScript crashes the game

Post 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!
Attachments
factorio-current.log
(9.67 KiB) Downloaded 111 times
Don't forget, you're here forever.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

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

Post 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.
If you want to get ahold of me I'm almost always on Discord.

User avatar
raiguard
Factorio Staff
Factorio Staff
Posts: 451
Joined: Wed Dec 13, 2017 8:29 pm
Contact:

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

Post 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.
Don't forget, you're here forever.

Post Reply

Return to “Resolved Problems and Bugs”