jdoleary / Spellmasons

https://store.steampowered.com/app/1618380/Spellmasons/
Other
0 stars 1 forks source link

Split - effectState.initialTargetedUnitId was defined but the unit was not found #822

Open SoulMuncher opened 1 week ago

SoulMuncher commented 1 week ago

It's really inconsistent, but I was able to repro it a few times on master branch in a 2 player localhost lobby Happens most consistently when spam casting Split / casting while other spells are currently running

P1 would split a unit into 4, P2 would only see 2 units, and ending turn/casting other spells wouldn't resolve the desync. If p1 targets a unit that exists on their client but not the other player's client, the effectState.initialTargetedUnitId error would be thrown

jdoleary commented 1 week ago

That's odd because split shouldn't change the id of the original unit. Is this during prediction?

SoulMuncher commented 1 week ago

This is not during prediction. I don't think it's changing the ID of the original unit. The resulting split units sometimes have different ID's on each client

Repro'd this again and devUnderworld.units.map(u => u.id) returned a different list of ID's on each client

On the caster-client, the unit with ID=8 was the same unit that had ID=7 on the non-caster-client, and many of the following units on the caster-client had ID+1 when compared to the non-caster-client.

After this, I created a new unit (ID=19 on caster, 18 on non-caster) and then tried to split it. On the caster-client, units with ID's 20+ were made. On the non-caster-client, the error was thrown, and the unit was not split.

Upon End Turn, the caster-client was synced to match the non-caster-client. All of the caster-client's units, unit id's, and unit stats were set = to what they would have been on the non-caster-client. Image scalers/sprite size was not correctly synced (A non-split golem had a sprite as if it were split 3, which it previously was on the caster-client, before the sync)

SoulMuncher commented 1 week ago

Network messages of type SyncPlayers, SyncSomeState, SetPhase, and Spell all sync underworld.lastUnitId. It seems likely to me that the queued up spell messages are somehow interfering with the network message/sync order, so it increments and gets synced back, or syncs forward early and increments an extra time, causing the discrepancy.

@jdoleary do you have any ideas? You're better at navigating the deep engine/networking stuff

jdoleary commented 1 week ago

Hmm that's a good thought. We might need to add some logic to throw away old syncs...