Page 1 of 1

[boskid][2.0.30] Crash taking screenshots via modding API, Optional.hpp check fails

Posted: Sun Jan 12, 2025 6:41 am
by Dot0
I am trying to make a mod that is capable of taking screenshots of the game at regular intervals among other tasks.
I'm using the game.takescreenshot function and whenever the show_gui, show_entity_info, or show_cursor_building_preview are set to true the game crashes.

The error log looks oddly similar to the forum thread 52878.

I tried solutions from there like disabling all game overlays from third party apps, and forcing openGL. I also tried all the suggestions in the common graphics error thread. 9300

I'm not keen on calling this a bug because I am quite new to modding Factorio. As such I created a video showing the lines of code that produce the error. I think this may be a syntax issue that I'm not aware of but I've tried many fixes. Anyway, the video is here:

https://www.dropbox.com/scl/fi/k050mlyl ... mir2f&dl=0

Re: [2.0.30] Crash taking screenshots via modding API, Optional.hpp check fails

Posted: Sun Jan 12, 2025 9:10 am
by Muche
Welcome to the forum, and thank you for the report.

This doesn't look graphics related.
More like it's trying to take a screenshot in the zeroth tick after loading a save, during which some gui stuff is not ready yet.

So it crashes with

Code: Select all

script.on_event(defines.events.on_tick, function(event)
  if game.tick ~= 0 then
    game.take_screenshot{
      show_gui = true,
...
but doesn't crash with (yes, this may be not multiplayer safe)

Code: Select all

local lasttick
script.on_event(defines.events.on_tick, function(event)
  if not lasttick then
    lasttick = game.tick
  else
    game.take_screenshot{
      show_gui = true,
...

Re: [2.0.30] Crash taking screenshots via modding API, Optional.hpp check fails

Posted: Sun Jan 12, 2025 9:30 am
by Dot0
Thank you so much! I knew it was probably my inexperience. It's okay that it's not multiplayer safe, it's just for collecting data.

Re: [2.0.30] Crash taking screenshots via modding API, Optional.hpp check fails

Posted: Sun Jan 12, 2025 9:37 am
by boskid
This issue should be now fixed for 2.0.31. When doing a screenshot for gui or for "building preview", the screenshot request was populated with cursor position however it look at this early stage it was not yet available and so it crashed trying to convert empty optional into a position.