Skip to content

bugfix(savegame): Restore particle system IDs before registation with ParticleSystemManager#2316

Open
stephanmeesters wants to merge 1 commit intoTheSuperHackers:mainfrom
stephanmeesters:bugfix-savegame-particlesystem-mapid
Open

bugfix(savegame): Restore particle system IDs before registation with ParticleSystemManager#2316
stephanmeesters wants to merge 1 commit intoTheSuperHackers:mainfrom
stephanmeesters:bugfix-savegame-particlesystem-mapid

Conversation

@stephanmeesters
Copy link

@stephanmeesters stephanmeesters commented Feb 16, 2026

Some savegames would error due to being unable to reconnect master/slave systems to a particle system.

This appeared to be caused because during xfer of the ParticleSystemManager, the particle systems would initially be assigned with a new (temporary) system ID, and only moments later be properly restored with xferSnapshot and receive the real system ID. However, particle systems were registered with ParticleSystemManager using this old invalid ID, which would cause lookup failures later.

The fix here is to defer the registration of particle systems with ParticleSystemManager until the system ID has been properly restored.

@greptile-apps
Copy link

greptile-apps bot commented Feb 16, 2026

Greptile Summary

This PR fixes a savegame loading crash where particle system master/slave lookups would fail due to ID mismatches. Previously, during xfer deserialization, particle systems were created via createParticleSystem() which assigned a temporary incrementing ID and immediately registered the system in the ParticleSystemManager map under that ID. When xferSnapshot() subsequently restored the real saved ID, the map entry still pointed to the old ID, causing findParticleSystem() lookups (used for master/slave reconnection) to fail.

The fix:

  • Constructs particle systems with INVALID_PARTICLE_SYSTEM_ID during xfer, bypassing registration in the constructor
  • Calls xferSnapshot() first to restore the correct ID from the save file
  • Validates the restored ID is not invalid before proceeding
  • Registers the system with friend_addParticleSystem() using the correct restored ID
  • Updates m_uniqueSystemID via MAX() as a safety net to prevent future ID collisions

The constructor change adds a guard if (m_systemID != INVALID_PARTICLE_SYSTEM_ID) which is backward-compatible — the normal createParticleSystem() path always provides a valid ID.

Confidence Score: 5/5

  • This PR is safe to merge — the fix is well-scoped, correct, and backward-compatible with the normal particle system creation path.
  • The change is minimal and targeted, addressing a clear root cause (ID mismatch during save/load). The constructor guard is backward-compatible since the normal createParticleSystem() always passes a valid ID. The xfer path now correctly defers registration until the real ID is restored. The MAX safeguard for m_uniqueSystemID prevents future ID collisions. No new code paths are introduced that could cause regressions.
  • No files require special attention

Important Files Changed

Filename Overview
Core/GameEngine/Source/GameClient/System/ParticleSys.cpp Fixes savegame particle system ID mismatch by deferring registration with ParticleSystemManager until after xferSnapshot restores the real system ID. Constructor guard and MAX safeguard for m_uniqueSystemID are both correct and backward-compatible.

Sequence Diagram

sequenceDiagram
    participant XM as ParticleSystemManager::xfer
    participant PS as ParticleSystem (constructor)
    participant XS as xferSnapshot
    participant PM as ParticleSystemManager (map)

    Note over XM: Before Fix (broken)
    XM->>PS: createParticleSystem(template) → assigns temp ID
    PS->>PM: friend_addParticleSystem(this) with temp ID
    XM->>XS: xferSnapshot(system) → restores real ID
    Note over PM: Map has temp ID → system, but system now has real ID
    XM->>PM: findParticleSystem(realID) → FAILS ❌

    Note over XM: After Fix (correct)
    XM->>PS: new ParticleSystem(template, INVALID_ID) → skips registration
    XM->>XS: xferSnapshot(system) → restores real ID
    XM->>XM: validate system ID != INVALID
    XM->>PM: friend_addParticleSystem(system) with real ID
    XM->>PM: findParticleSystem(realID) → SUCCESS ✓
Loading

Last reviewed commit: 7cbe0ab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Savegame error due to ParticleSystem master/slave not able to reconnect

1 participant