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

This subforum contains all the issues which we already resolved.
Dot0
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sun Jan 12, 2025 6:28 am
Contact:

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

Post 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
Attachments
factorio-previous.log
(11.22 KiB) Downloaded 10 times
Muche
Filter Inserter
Filter Inserter
Posts: 597
Joined: Fri Jun 02, 2017 6:20 pm
Contact:

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

Post 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,
...
Dot0
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sun Jan 12, 2025 6:28 am
Contact:

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

Post 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.
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 3411
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

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

Post 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.
Post Reply

Return to “Resolved Problems and Bugs”