Skip to content

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

Open
stephanmeesters wants to merge 3 commits intoTheSuperHackers:mainfrom
stephanmeesters:bugfix-savegame-particlesystem-mapid
Open

bugfix(savegame): Restore particle system IDs before registation with ParticleSystemManager#2316
stephanmeesters wants to merge 3 commits 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

Fixes a savegame loading bug where particle systems were registered in ParticleSystemManager with temporary IDs before their real IDs were restored via xferSnapshot, causing master/slave system lookups to fail.

  • Defers friend_addParticleSystem registration during ParticleSystemManager::xfer until after xferSnapshot restores the correct system ID.
  • Guards the constructor's friend_addParticleSystem call behind an INVALID_PARTICLE_SYSTEM_ID check so systems created with an invalid ID are not prematurely registered.
  • Adds a post-xferSnapshot validation that the system ID was properly restored, with a DEBUG_CRASH and exception on failure.
  • Bypasses createParticleSystem (which increments m_uniqueSystemID) in favor of direct construction, which is correct since m_uniqueSystemID is already restored from the save data.

Confidence Score: 4/5

  • This PR is a well-reasoned bugfix that correctly addresses the root cause of savegame load failures with minimal risk to existing functionality.
  • The fix correctly identifies and addresses the root cause: particle systems were registered with temporary IDs before deserialization restored their real IDs, causing subsequent master/slave lookups to fail. The approach is clean — deferring registration until after ID restoration — and the constructor guard ensures the normal (non-xfer) creation path remains unaffected. Minor concern: on the error path (xferSnapshot throws or ID remains invalid), the allocated system object is not explicitly freed before the exception propagates, but this matches the pre-existing error handling pattern in this function.
  • No files require special attention beyond normal review.

Important Files Changed

Filename Overview
Core/GameEngine/Source/GameClient/System/ParticleSys.cpp Defers particle system registration with ParticleSystemManager until after system ID is restored from save data, fixing master/slave lookup failures. The fix is logically sound and well-targeted.

Sequence Diagram

sequenceDiagram
    participant SM as ParticleSystemManager::xfer
    participant PS as ParticleSystem (new)
    participant XF as Xfer (xferSnapshot)

    Note over SM: Old (buggy) flow
    SM->>SM: createParticleSystem(template, FALSE)
    SM->>PS: constructor(template, m_uniqueSystemID++, FALSE)
    PS->>SM: friend_addParticleSystem(this) [temp ID]
    SM->>XF: xferSnapshot(system)
    XF->>PS: restores real m_systemID
    Note over SM: systemMap has wrong ID → lookup fails

    Note over SM: New (fixed) flow
    SM->>PS: constructor(template, INVALID_PARTICLE_SYSTEM_ID, FALSE)
    Note over PS: Skips friend_addParticleSystem (ID is invalid)
    SM->>XF: xferSnapshot(system)
    XF->>PS: restores real m_systemID
    SM->>SM: friend_addParticleSystem(system) [correct ID]
    Note over SM: systemMap has correct ID → lookups succeed
Loading

Last reviewed commit: e962c05

Copy link

@xezon xezon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very good. Nice find.

DEBUG_CRASH(( "ParticleSystemManager::xfer - Unable to allocate particle system '%s'",
if( system->getSystemID() == INVALID_PARTICLE_SYSTEM_ID )
{
DEBUG_CRASH(( "ParticleSystemManager::xfer - Unable to restore system ID to particle system '%s'",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete system on error

@xezon xezon added Bug Something is not working right, typically is user facing Major Severity: Minor < Major < Critical < Blocker Saveload Is Saveload/Xfer related labels Feb 17, 2026
@xezon xezon added this to the Major bug fixes milestone Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something is not working right, typically is user facing Major Severity: Minor < Major < Critical < Blocker Saveload Is Saveload/Xfer related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants