Hi MrJakobLaich / Maoman,
I saw the earlier comments here:
- ashragnorok reported the crash with a belt balancer blueprint
- Fortheking55 mentioned huge lag spikes when placing blueprints
- Raukie found the workaround: disable companion auto-build, place the blueprint, then turn it back on
- Maoman wrote that the blueprint code mostly comes from the original author and tends to break whenever touched
We hit the same crash on Factorio 2.0.77 with companion-drones-mjlfix 3.1.2:
Error while running event companion-drones-mjlfix::on_pre_build (ID 9)
LuaItemStack doesn't contain key contents.
Stacktrace:
companion-drones-mjlfix/script/companion.lua:2252
in get_all_blueprint_entities()
called from get_blueprint_area()
called from on_pre_build
The workaround from Raukie also makes sense with what we saw: the crash only happens when companion construction / auto-build is active and the mod tries to inspect the blueprint in on_pre_build.
We tested a minimal defensive fix on our server. The goal was not to rewrite the fragile blueprint logic, only to avoid the server crash.
Root cause seems to be this line:
for _, item in pairs(blueprint_record.contents) do
That works when the object exposes contents, but crashes when the cursor blueprint/book is represented as a LuaItemStack or item-backed blueprint book.
Our tested fix was:
- Add a small helper like
get_blueprint_book_children(record).
- First try
record.contents through pcall.
- If that fails, try
record.get_inventory(defines.inventory.item_main) and iterate valid inventory slots.
- Replace direct
blueprint_record.contents iteration with that helper.
- Wrap calls to
get_all_blueprint_entities() from get_blueprint_area() in pcall, so unknown cursor/blueprint states get ignored instead of crashing the whole server.
After this patch:
- the server no longer crashes on the problematic blueprint
- companion construction still works for our tested case
- if the mod cannot understand a blueprint object, it falls back safely instead of killing the multiplayer session
So this may be a low-risk guard around the existing blueprint code rather than a major blueprint rewrite.
I can provide the exact diff if that helps.