An advanced combinator that can modify the research queue and output research-related signals based on input signals.
Providing the player with new tools or adjusting the game interface, without fundamentally changing gameplay.
Entities which interact with the circuit network.
"The mod Research Automation Combinator (1.0.2) caused a non-recoverable error." (Factorio version 2.0.76)
This mod seems very fragile.
I am playing a custom modpack that adds (and modifies) a bunch of Research Technologies and found these crashes when trying to set up an automated research selector circuit. It's sad to see that it doesn't work. (I didn't test for further edge cases, these are just the ones that were imminently visible)
When unticking "Read Research Progress" ("value" has index 2, "percentage" has index 1):
Error while running event research-automation-combinator::on_gui_checked_state_changed (ID 3)
Index out of bounds. index: 2, size: 0
stack traceback:
[C]: in function 'remove_output'
...-combinator__/scripts/research-automation-combinator.lua:925: in function 'remove_output'
...-combinator__/scripts/research-automation-combinator.lua:456: in function 'update_combinator'
research-automation-combinator/scripts/gui.lua:534: in function 'update_object_from_gui'
research-automation-combinator/scripts/gui.lua:654: in function <research-automation-combinator/scripts/gui.lua:638>
Note for the above: When "Read current researched" is ticked, both the index and bound size increase by 1
When unticking "Read Research Status":
Error while running event research-automation-combinator::on_gui_checked_state_changed (ID 3)
Index out of bounds. index: 102, size: 101
stack traceback:
[C]: in function 'remove_output'
...-combinator__/scripts/research-automation-combinator.lua:967: in function 'remove_research_status_outputs'
...-combinator__/scripts/research-automation-combinator.lua:994: in function 'on_research_change'
...-combinator__/scripts/research-automation-combinator.lua:462: in function 'update_combinator'
research-automation-combinator/scripts/gui.lua:534: in function 'update_object_from_gui'
research-automation-combinator/scripts/gui.lua:654: in function <research-automation-combinator/scripts/gui.lua:638>
When changing any ticked value inside "Read Research Status" (when it's ticked):
Error while running event research-automation-combinator::on_gui_checked_state_changed (ID 3)
Index out of bounds. index: 1266, size: 1149
stack traceback:
[C]: in function 'remove_output'
...-combinator__/scripts/research-automation-combinator.lua:967: in function 'remove_research_status_outputs'
...-combinator__/scripts/research-automation-combinator.lua:994: in function 'on_research_change'
...-combinator__/scripts/research-automation-combinator.lua:462: in function 'update_combinator'
research-automation-combinator/scripts/gui.lua:534: in function 'update_object_from_gui'
research-automation-combinator/scripts/gui.lua:654: in function <research-automation-combinator/scripts/gui.lua:638>
When "Available Technologies" is selected (inside the ticked "Read Research Status") and a Research finishes:
Error while running event research-automation-combinator::on_research_finished (ID 22)
Index out of bounds. index: 52, size: 43
stack traceback:
[C]: in function 'remove_output'
...-combinator__/scripts/research-automation-combinator.lua:967: in function 'remove_research_status_outputs'
...-combinator__/scripts/research-automation-combinator.lua:994: in function 'on_research_change'
research-automation-combinator/control.lua:31: in function 'on_research_change'
research-automation-combinator/control.lua:100: in function <research-automation-combinator/control.lua:99>
It all circles back to the "remove_output" function.
The on_research_finished size 43 is the actual amount of available researches, where it pulls the extra 9 from is unclear but it doesn't seem to correlate with technologies that are unlocked in theory but locked behind other locked technologies (which would have been my theory).
Took a look and found a spot where the internal tracking list can get out of sync. I also added a bit more defensive checks - so if it messes up it won't cause a crash. I'll get a release out shortly.
It's done this way for performance (setting the the outputs on a "fake" combinator is way more performant than having to create signal outputs every tick).
Checking the github pre-release, the crashes sadly still persist
Which one? Did you pick up the latest change (e56f226) or was it the first push (5670263)?
I redownloaded the latest repo just in case.
And something did change: Instead of the mod crashing when unticking a UI element, Factorio itself crashes
I redownloaded the latest repo just in case.
And something did change: Instead of the mod crashing when unticking a UI element, Factorio itself crashes
Not unticking, Factorio already crashed when ticking any checkbox
(Don't mind the edits, I cannot goddamn speak this language)
Yuuup, does it on mine too, let me keep working on it.
I've been running with this fix for a couple weeks, and haven't had any crashes: https://github.com/jrossignol/research-automation-combinator/pull/2.
Also, what's the reason for manually tracking the next free index, rather than just doing #cb.parameters.outputs+1?
Honestly it's may not be needed, can't 100% remember why. It might be because in some places I didn't have the CombinatorBehaviour, and the call to get it is expensive if it's being done unnecessarily in on_tick().
Version 1.0.3 still crashes btw.
Most tick boxed don't crash upon unchecking anymore but I cannot select "Available technologies" without it erroring. (Even with the proposed fix from yut23)
Error while running event research-automation-combinator::on_gui_checked_state_changed (ID 3)
Index out of bounds. index: 113, size: 111
stack traceback:
[C]: in function 'add_output'
...-combinator__/scripts/research-automation-combinator.lua:1133: in function 'on_research_change'
...-combinator__/scripts/research-automation-combinator.lua:462: in function 'update_combinator'
research-automation-combinator/scripts/gui.lua:534: in function 'update_object_from_gui'
research-automation-combinator/scripts/gui.lua:654: in function <research-automation-combinator/scripts/gui.lua:638>
Idea:
Check if the the index is out of bounds before using it.
If it is, pull the updated info and print the difference to the chat so we have more insight on the situation/what technologies are causing trouble.
(I'll gladly play the guinea pig for testing)
You can try using this branch, it prints tons of extra debug info to the game chat and adds more internal state checks: https://github.com/yut23/research-automation-combinator/tree/extra-debug-logging
It prints a bunch of text that very quickly goes out of view. (Maybe use print() so I can copy the full info from the log file? I don't know a lot about the API factorio provides :])
*It's log(), not print()
After clicking around a little more this also occured:
Error while running event research-automation-combinator::on_gui_checked_state_changed (ID 3)
...-combinator__/scripts/research-automation-combinator.lua:327: assertion failed!
stack traceback:
[C]: in function 'assert'
...-combinator__/scripts/research-automation-combinator.lua:327: in function 'check_next_free'
...-combinator__/scripts/research-automation-combinator.lua:1306: in function 'on_research_change'
...-combinator__/scripts/research-automation-combinator.lua:559: in function 'update_combinator'
research-automation-combinator/scripts/gui.lua:534: in function 'update_object_from_gui'
research-automation-combinator/scripts/gui.lua:654: in function <research-automation-combinator/scripts/gui.lua:638>
Updated to output to the log file as well (factorio-current.log in https://wiki.factorio.com/Application_directory#User_data_directory)
Can you try to reproduce that crash and grab the NEXT_FREE mismatch: ... line and the following one (indexes: ...) out of the log?
(also, I recently learned that exiting to the main menu and reloading a save is enough for these control script changes; no need to relaunch the whole game)
Oh! That'll saves so much time, reloading the games takes ~5min
Here is the log:
265.393 Script @research-automation-combinator/scripts/research-automation-combinator.lua:76: [24128 DEBUG] on_research_change(), line 1306: final indexes = {R_STATUS_START=1, R_STATUS_END=53, NEXT_FREE=54}
265.394 Script @research-automation-combinator/scripts/research-automation-combinator.lua:76: [24128 DEBUG] check_next_free(), line 326: NEXT_FREE mismatch: value = 54, #outputs = 31
265.394 Script @research-automation-combinator/scripts/research-automation-combinator.lua:76: [24128 DEBUG] check_next_free(), line 327: indexes: {R_STATUS_START=1, R_STATUS_END=53, NEXT_FREE=54}
265.394 Script @research-automation-combinator/scripts/research-automation-combinator.lua:76: [24128 DEBUG] check_next_free(), line 328: outputs (31):
Followed by these
{copy_count_from_input = false, networks = {green = true, red = true}, signal = {name = "rac-technology-braking-force-1", type = "virtual"}}
{copy_count_from_input = false, networks = {green = true, red = true}, signal = {name = "rac-technology-crushed-ore-smelting-productivity-2", type = "virtual"}}
{copy_count_from_input = false, networks = {green = true, red = true}, signal = {name = "rac-technology-defender", type = "virtual"}}
{copy_count_from_input = false, networks = {green = true, red = true}, signal = {name = "rac-technology-diesel-automation", type = "virtual"}}
{copy_count_from_input = false, networks = {green = true, red = true}, signal = {name = "rac-technology-electric-energy-distribution-2", type = "virtual"}}
... (I cut out a bunch to make it shorter)
265.394 Error MainLoop.cpp:1468: Exception at tick 6424128: The mod Research Automation Combinator (1.0.3) caused a non-recoverable error.
Please report this error to the mod author.
Error while running event research-automation-combinator::on_gui_checked_state_changed (ID 3)
...-combinator__/scripts/research-automation-combinator.lua:329: assertion failed!
stack traceback:
[C]: in function 'assert'
...-combinator__/scripts/research-automation-combinator.lua:329: in function 'check_next_free'
...-combinator__/scripts/research-automation-combinator.lua:1308: in function 'on_research_change'
...-combinator__/scripts/research-automation-combinator.lua:561: in function 'update_combinator'
research-automation-combinator/scripts/gui.lua:534: in function 'update_object_from_gui'
research-automation-combinator/scripts/gui.lua:654: in function <research-automation-combinator/scripts/gui.lua:638>
Which input did you click right before the crash?
Clicking the other option "Unresearched Technologies" does the same as "Available Researches"
Okay, I think I figured it out, try again with the latest commit. Have you added or removed any mods that added technologies since installing RAC?
Since installing RAC, the mod list hasn't changed but that may be irrelevant as it doesn't crash anymore!
I don't know if it's 100% fool proof but clicking around seems pretty stable now.
Updating the outputted signals also seems to work properly, well done.
Great! The code was using the wrong output count when a RAC technology virtual signal didn't exist. I'm not sure what would cause that, but there's a comment that says "Check if the virtual signal exists (it may not if a mod was removed)." Do you mind posting your mod list and maybe looking through the Technology tab in Factoriopedia to see if there are any techs missing there?
I did notice another bug while testing myself: toggling the Output Signals checkboxes off (lower left panel) doesn't actually remove the output signals.
Filtering the 224 mod modpack for only for those which have a technology prototype, these 37 mods stand out:
aai-vehicles-ironclad_0.7.5
Flare Stack_4.1.0
est-tiny-storage-tank_1.4.0
liquid_recycler_1.0.12
minimalist-rails_2.0.5
hd-plasma-duct_1.1.10
Accumulator-V2_1.0.6
crane-builder_1.5.1
canal-excavator_1.13.3
apia_0.2.0
casting_plant_1.0.6
Cerys-Moon-of-Fulgora_4.21.7
Cloning-vat-building_1.0.4
crushing-industry_0.5.10
molten_plastic_1.0.34
moon-eneas_0.6.10
Moshine_1.1.3
obsidiax_0.1.08
Paracelsin_1.7.4
planet-crucible_0.3.7
planet-muluna_2.1.78
plasma_crafter_1.0.24
plasma_handling_1.0.2
rec-blue-plus_1.4.16
RenaiTransportation_2.2.10
ribbonia_0.2.28
rigor-module_0.4.1
Robocharger-Updated_0.0.1
rubia_0.69.140
secretas_1.0.33
shchierbin_0.3.13
skewer_planet_vesta_2.1.13
SolarMatrix_1.0.6
SpidertronPatrols_2.6.4
tenebris-prime_1.3.8
terrapalus_0.2.8
Though I do remember tinkering with some mod settings which could have caused a few technologies to be removed.
Is there no event for when a scenario loads where one would be able to refresh the cached technologies?
Also:
The output for "Get science packs for technology" also doesn't update properly (' didn't test the others).
Old values are retained when witching input signals
That should be fixed by https://github.com/jrossignol/research-automation-combinator/pull/4.
Let me know if yut23's changes on their own fix your issues - I'd already made both those fixes in my working copy, but there's a few other bugs that I'm working through (mostly to do with cleaning up state on mod state changed - and yes, there is an event for that).
I am sorry for the 2 week delay but no crash seems to occur anymore.
Well Done.