Page 1 of 1

[1.1.104] Crash using Camera UI Elem at high zoom far away from spawn

Posted: Wed Jan 31, 2024 10:08 am
by nnotm
If you use a LuaGuiElement of type "camera" with large zoom values far away from the spawn point, the game will crash, saying

Code: Select all

Error FloatCast.hpp:123: 2159999906.000000 > 2147483647.000000
(or similar numbers).

I originally encountered this when trying to use the area outside the world map to draw graphs - at the position I randomly selected, it crashed at zoom values as low as 10. The further out you go, the lower the critical zoom value becomes, but you don't have to go outside of the playable area for this to happen (see code below).

I would have expected to be able to zoom in as far as I want to.
Reproduction steps
I have a copy of 1.1.104 with just one mod enabled containing this control.lua file:

Code: Select all

script.on_event(defines.events.on_gui_closed, function(event)
    local player = game.get_player(1)
    if player then
        local frame = player.gui.screen.add{type="frame", name="frame"}
        frame.auto_center = true
        local camera = frame.add{
            type="camera",
            position={900000, 0},
            zoom=75,
        }
        camera.style.size = {200, 200}
    end
end)
You can either make a mod containing this or just run `/c <that code>` in the console after starting a new game.

You can then reproduce the crash by opening and then closing the inventory interface.

Re: [1.1.104] Crash using Camera UI Elem at high zoom far away from spawn

Posted: Thu Feb 01, 2024 4:25 pm
by Rseding91
Thanks for the report. This is now fixed for 2.0. In the meantime you can use an empty surface and just do the rendering closer to 0,0 :)

Re: [1.1.104] Crash using Camera UI Elem at high zoom far away from spawn

Posted: Thu Feb 01, 2024 9:39 pm
by nnotm
Thanks! To make sure I head in the right direction with my mod, can I ask if the fix is just preventing the crash or if it also involves being able to zoom in as far as you want?

Re: [1.1.104] Crash using Camera UI Elem at high zoom far away from spawn

Posted: Thu Feb 01, 2024 9:40 pm
by Rseding91
I believe zoom should work as desired with the fix.

Re: [1.1.104] Crash using Camera UI Elem at high zoom far away from spawn

Posted: Thu Feb 01, 2024 9:46 pm
by nnotm
Very cool, thanks