Feedback on compatibility.

Hoochie Hoochie · 2 months ago

Hello!

Just some feedback. You've marked the industrial mod as incompatible, but that's not a very good solution, since that mod adds quite a lot of content, and instead of that content, you're suggesting replacing it with just the splitters.

Probably a better solution would be to create a separate category for these splitters, and let the user decide which ones to use, rather than blocking other content from mods.

Mr.Ficarazzi Mr.Ficarazzi · 25 days ago

Hi Alan,

I found a save-breaking bug in Multi-Priority Balancers 0.2.1 (game 0.8.7d) and tracked down the cause. Sharing the details and a possible fix.

SYMPTOM
After restarting the game, every save containing P1/P2/P3 balancers fails to load:
CorruptedSaveException: Failed to finalize deserialization of 'Zipper #0 (destroyed)' ... Deserialized object has type 'String' but type 'LystMutableDuringIter`1' was expected.

ROOT CAUSE
EarlyInit() calls new Harmony(id).PatchAll() every time a game is built, and EarlyInit runs on each new game and on each load in the same session. Harmony does not deduplicate, so after a second load in one session every patch is applied twice.
With two SavePriorityLevels postfixes on Zipper.SerializeData, each MPB balancer writes its priority block twice (count + levels, then the same again). After a game restart only one LoadPriorityLevels postfix exists, so one copy stays unread and the next delayed object is read misaligned, which gives the 'Zipper #0 (destroyed)' error.
I checked this against a real broken save: all 10 MPB balancers had the block exactly twice, followed directly by the next entity. Removing the second copies made the save load fine.
Side effect (likely, not checked in-game): in a double-patched session the processInputProducts / tryReleaseFirstProduct prefixes also run twice per tick.

REPRO

  1. Start the game and load a save with MPB balancers (or start a new game).
  2. Without restarting, load any save again.
  3. Save, quit the game, restart, load that save: it crashes.

SUGGESTED FIX
Patch only once per process:

public override void EarlyInit(...)
{
base.EarlyInit(...);
if (Harmony.HasAnyPatches("Alan2623.MultiPriorityBalancers")) return;
m_harmony = new Harmony("Alan2623.MultiPriorityBalancers");
m_harmony.PatchAll(Assembly.GetExecutingAssembly());
}

(a static bool flag works too)

Optional, to rescue saves already written by 0.2.1: in LoadPriorityLevels, after reading the block, peek ahead and skip any immediately following identical block (same count + same bytes). Note that during a normal load the BlobReader stream is a BufferedReadStream over GZip, so it is not seekable. I peeked inside its buffer.
For the future, a format/version byte in front of your data would make changes like this easier to handle.

I applied both changes as a local binary patch to my copy (0.2.2 'unofficial'). The double-patch fix and the duplicate skipping passed tests outside the game. In-game I only checked that the repaired save loads; the patched DLL itself hasn't been played yet. I can share the patched DLL or the broken save if useful.

Thanks for the mod, the priorities are really handy!
Isodoro

133 Showing 1–3 of 3