Skip to content

fix(spectator): rebuild the overview instead of showing an empty grid - #232

Open
TheMeinerLP wants to merge 1 commit into
mainfrom
fix/spectator-overview-refresh
Open

fix(spectator): rebuild the overview instead of showing an empty grid#232
TheMeinerLP wants to merge 1 commit into
mainfrom
fix/spectator-overview-refresh

Conversation

@TheMeinerLP

Copy link
Copy Markdown
Contributor

Proposed changes

The spectate overview showed no survivors at all, even while survivors were still alive.

Root cause: SpectatorInventory is constructed in the Cygnus constructor at server start, and its register() call builds the inventory and computes the data layout right there, at a point where the survivor team is still empty. The head list was never rebuilt afterwards. Aves' InventoryBuilder#invalidateDataLayout only clears the valid flag while nobody has the inventory open, and the following GlobalInventoryBuilder#getInventory skips the rebuild: it computes applyLayout from the design layout flag, and updateInventory(inventory, locale, false) returns before it ever reaches the retrieveDataLayout branch. So the empty list from server start stayed for the whole round.

Fix: a SpectatorInventory#refresh that invalidates both layouts, called from open and from SpectatorService#updateInventory (which the death and quit listeners already drive). Invalidating the design layout as well is also what clears the inventory. A data layout can only write items: applyDataLayout skips null and air stacks, so a blanked slot is never written back and the head of a player who left the round would otherwise stay in place and stay clickable.

Types of changes

What types of changes does your code introduce to this project?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of
them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before
merging your code.

  • I have read the CONTRIBUTING.md
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

Two tests come with the fix, both failing on main:

  • SpectatorInventoryTest#testOpenPicksUpSurvivorsThatJoinedAfterTheInventoryWasBuilt reproduces the production order, meaning the inventory is built while the team is still empty and survivors join later.
  • SpectatorInventoryTest#testOpenDropsHeadsOfPlayersThatLeftTheSurvivorTeam covers the stale head.

The fix stays inside this repo and uses only Aves' public API, so no Aves release is needed. Worth noting that the same limitation would bite any other Aves inventory whose data layout changes while it is closed.

The companion PR on branch fix/spectator-flight-cooldown fixes the spectator flight and stamina bugs. The two touch SpectatorService in different places and merge onto main without a conflict, and both were verified merged together with a green ./gradlew build.

The overview listed no survivors at all. Its inventory is built once, at
server start, when the survivor team is still empty, and the head list was
never rebuilt afterwards: invalidating the data layout only clears a flag
while nobody has the inventory open, and the following getInventory skips the
rebuild because it retrieves a data layout only while it applies the design
layout as well.

Invalidating both layouts on open and on every roster change fixes that and
also clears the inventory, which a data layout cannot do on its own - the head
of a player who left the round would otherwise stay in place and stay
clickable.
@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Test results

  336 files    336 suites   2m 6s ⏱️
  479 tests   473 ✅  6 💤 0 ❌
1 440 runs  1 422 ✅ 18 💤 0 ❌

Results for commit 49704f8.

Comment on lines +145 to +148
public void refresh() {
this.invalidateLayout();
this.invalidateDataLayout();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is just a hotfix for the inventory update and does not address the underlying issues.

With this approach, every time a player opens the inventory, all items aligned with the background and data layers are recalculated. A proper fix would be to identify the specific positions where the data layout needs to be invalidated and only recalculate those positions when necessary, rather than triggering a full recalculation on every inventory open.

*/
public void updateInventory() {
this.spectatorInventory.invalidateDataLayout();
this.spectatorInventory.refresh();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See above

@theEvilReaper theEvilReaper added the area: game Everything related to the the game module label Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: game Everything related to the the game module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants