Fix Shadow Corruption from Stale DynaPoly floorPoly Pointers#6616
Open
unreference wants to merge 2 commits into
Open
Fix Shadow Corruption from Stale DynaPoly floorPoly Pointers#6616unreference wants to merge 2 commits into
unreference wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes #1953.
Actors that cache
floorPolypointers into the DynaPolypolyListbuffer can end up holding stale references whenDynaPoly_ExpandSRTrebuilds the buffer. The pointer address remains valid, but the data at the address shifts to a different polygon -- often a wall poly with a horizontal normal.When this happens, the shadow projection matrix is built from the wall normal instead of a floor normal, rotating the shadow 90-degrees onto a vertical plane. Combined with
G_CULL_BACKinsSetupDL[0x2C], the shadow flickers in and out depending on camera angle. This bug also exists on original hardware, but likely masked by the constraints.normal.y > 0guard so polys that no longer face upward are rejected before the shadow matrix is built. Prevents rendering from any stale wall or ceiling poly.DYNAPOLY_INVALIDATE_LOOKUPtriggers a full rebuild inDynaPoly_Setup, rederivefloorPolyviaBgCheck_EntityRaycastFloor5for every actor whosefloorBgIdreferences a DynaPoly surface. This only runs on frames where the invalidation flag is set and only touches a small subset of actors on dynamic collision, so there is effectively zero performance cost.What I couldn't figure out is why this is specifically caused by destroying a crate. The crate itself is not DynaPoly, and nothing in its destruction path calls DynaPoly functions, yet destroying multiple crates continuously flips the shadow. The fix is sound regardless because the bug itself is systemic -- any actor holding a stale
floorPolypointer into the DynaPoly buffer can also experience it -- this specific actor's one-shot BgCheck just makes it easier to trigger.