Skip to content

Fix district-related building desyncs and crashes#128

Open
SamuZad wants to merge 2 commits intothomaswp:devfrom
SamuZad:feat/improve-district-desyncs
Open

Fix district-related building desyncs and crashes#128
SamuZad wants to merge 2 commits intothomaswp:devfrom
SamuZad:feat/improve-district-desyncs

Conversation

@SamuZad
Copy link
Copy Markdown
Contributor

@SamuZad SamuZad commented Mar 15, 2026

Fixes #81 and #125

Placing district centers and district center crossings are more sensitive than other buildings. Their placement by the host would "reliably" cause desyncs (with the district center) and crashes (with district center crossings).

The problem was that the act of placing by the host would render that location "invalid" when it was replayed back at the host

The clients had no such issues, they could place these objects just fine.

@SamuZad SamuZad force-pushed the feat/improve-district-desyncs branch 2 times, most recently from 4693d06 to 100e676 Compare March 15, 2026 20:18
@SamuZad SamuZad changed the title Fix district center desync issues by executing placements immediately WIP: Fix district center desync issues by executing placements immediately Mar 15, 2026
@SamuZad SamuZad force-pushed the feat/improve-district-desyncs branch from 100e676 to 4dc6837 Compare March 15, 2026 20:22
@robinplace
Copy link
Copy Markdown
Collaborator

robinplace commented Mar 16, 2026

The district center desync I reported, in issue #125, is from the client side. Sounds like that one's going to be harder to reproduce. It is probably a separate issue from this though.

@robinplace
Copy link
Copy Markdown
Collaborator

robinplace commented Mar 16, 2026

It looks like #96 is also a district center-placing desync that would be fixed by this.

@SamuZad SamuZad force-pushed the feat/improve-district-desyncs branch from 4dc6837 to 796fc69 Compare March 17, 2026 22:43
@SamuZad SamuZad force-pushed the feat/improve-district-desyncs branch from 796fc69 to dd49b03 Compare March 21, 2026 16:12
@SamuZad SamuZad changed the base branch from master to dev March 21, 2026 16:13
@SamuZad
Copy link
Copy Markdown
Contributor Author

SamuZad commented Mar 21, 2026

@thomaswp I changed things to be more tailor-made to the problem at hand

  1. Skip IsPlacementValid for district centers - this was causing the instant desyncs
  2. Add various Harmony finalizers that suppress duplicate registration exceptions, both for district centers and district crossings
  3. Also handle the deconstruction of an "in-use" district center

I have verified that these stop all district-related desyncs/crashes, and cause no immediate population-related desyncs. (The caveat is that I only tested population stuff for about 20 minutes, so there might be more subtle things with large populations and extended game sessions - I will try to do some more thorough testing)

In the meanwhile, could you let me know what you think about the approach?

@SamuZad SamuZad changed the title WIP: Fix district center desync issues by executing placements immediately Fix district center desync issues by executing placements immediately Mar 22, 2026
@SamuZad
Copy link
Copy Markdown
Contributor Author

SamuZad commented Mar 22, 2026

I have now played with this change for an extended time placing multiple district centers and crossings, and found no issues. So I'm confident enough to no longer call this a work in progress

@robinplace
Copy link
Copy Markdown
Collaborator

Hey @SamuZad I like the new approach. The title of this PR could use an update to reflect it!

@SamuZad SamuZad changed the title Fix district center desync issues by executing placements immediately Fix district-related building desyncs and crashes Mar 22, 2026
@uschigras1-gif
Copy link
Copy Markdown

error-report-2026-03-25-20h10m27s.zip
We can reproduce this in our game: when we create a district hub, the game crashes. Attached is the error log.

@thomaswp
Copy link
Copy Markdown
Owner

thomaswp commented Mar 28, 2026

Thanks for this! Ok, so am I understanding correctly that:

  • Checking for valid placement with District Centers doesn't work, so you skipped that
  • But there can still be many problems with their placement when the mod tries to replay the logic, so you had to address those exceptions that arise from valid? Specifically, it sounds like the game expects some of the valid placement logic to be handled by the state of the tool/preview UI, but since we're disconnecting those, it bugs out - is that right?

Is that issue that a valid placement still causes errors, so you have to suppress them? Is that because of the second bullet above?

Or is the issue just that to catch invalid placements in a way that doesn't break things, you need these finalizers?

I guess my concern is that this logic seems very likely to break if the devs change anything about district centers (even string literals). If possible I'd love a more robust fix, but if it's not then it's good to have a fix, even if we have to update it.

@SamuZad
Copy link
Copy Markdown
Contributor Author

SamuZad commented Mar 28, 2026

Checking for valid placement with District Centers doesn't work, so you skipped that
This is correct

Is that issue that a valid placement still causes errors, so you have to suppress them? Is that because of the second bullet above?

Yes, this is true both for district centers and crossings - even valid placements (and deconstructions) were causing issues.

The current solution handles both valid and invalid placements reasonably well, but I do agree that it is very "tailor-made". However, I couldn't think of any better way to handle it, so I think it would make sense to merge this

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.

Game crash when placing district crossing

4 participants