Fix swapped d22/d23 in call_RMTMatrix_Relative ELSE branch#4
Open
patrickoshaughnessey wants to merge 1 commit into
Open
Fix swapped d22/d23 in call_RMTMatrix_Relative ELSE branch#4patrickoshaughnessey wants to merge 1 commit into
patrickoshaughnessey wants to merge 1 commit into
Conversation
The ELSE branch (taken when the parent is not an RMTObject — i.e. for sectors directly under root) used a `SELECT ... INTO ...` pattern with `mr.d23` and `mr.d22` listed in the wrong order against the `d20, d21, d22, d23` INTO list. In MySQL, `SELECT ... INTO ...` is positional, so this silently assigned local `d22 := mr.d23` and `d23 := mr.d22`. The matrix-to-transform extraction then computed `Transform_Scale_dZ = SQRT(... d22²) = 0` and `Transform_Position_dZ = d23` from the wrong column, persisting `scale.z = 0` and `position.z = <translation z>` to the RMTObject row even though the underlying matrix was correct. Reads from the row returned the corrupt values; subscriptions propagated them to clients. The SQL Server version had the same out-of-order textual layout but the syntax there is `@var = column` (assignment by name, not position), so it was cosmetic only. Fix both for consistency so the parallel MySQL bug isn't reintroduced by copying the SQL Server pattern. Verified on a live database: a sector whose row had been corrupted self-healed to the correct values on the next transform update after the procedure was reloaded.
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.
Summary
call_RMTMatrix_Relative's ELSE branch has the column references formr.d23andmr.d22listed in the wrong order in theSELECT ... INTO ...clause. In MySQL,SELECT ... INTO ...is positional, so this silently swaps the values:d22 := mr.d23(should have beenmr.d22)d23 := mr.d22(should have beenmr.d23)The subsequent transform extraction then computes:
Transform_Scale_dZ = SQRT(d02² + d12² + d22²) = 0— because locald22now holds the translation columnTransform_Position_dZ = d23— because locald23now holds the diagonal scale entryThese corrupt values get written back to the
RMTObjectrow by theUPDATEat the end of the procedure, even though the actualRMTMatrixrow is correct. Subsequent reads of the row return the corrupt values, and subscriptions propagate them to all clients.The bug only affects objects whose parent class is not
RMTObject(i.e. sectors parented directly under root). Parcels and physicals go through the IF branch, which uses inline matrix-multiplication expressions whose textual order naturally matches the INTO list, so the bug doesn't manifest there.It also only affects the z components. Position-y/scale-y come from
d13/d11, which aren't reordered. That's whyupdate_objectcalls that include a non-default y stuck while z reverted to whatever the swapped extraction produced.Root cause
In MySQL, the third value in the SELECT list (
mr.d23) is assigned to the third INTO target (d22), and the fourth (mr.d22) is assigned tod23. Result: a stable, asymptomatic-on-write but corrupt-on-read state for any sector that has been transform-updated.Fix
Restore canonical column order so SELECT and INTO agree:
The SQL Server version of the same proc had the identical out-of-order textual layout, but SQL Server's syntax is
SET @var = column(assignment by name, not position), so it was cosmetic only. This PR also fixes the SQL Server file for consistency, so future contributors don't propagate the bad pattern back into MySQL.Verification
Reproduced on a live deployment with a corrupted sector row and verified end-to-end:
RMTObjectrow hadPosition_dZ=1, Scale_dZ=0despite the correspondingRMTMatrixrow havingd22=1, d23=0.call_RMTMatrix_Relativefrom the patched file.update_objecttransform call to the sector.Position_dZ=0, Scale_dZ=1— matching the matrix.Notes for ops
Any sectors in production that have been transform-updated under the buggy procedure currently have corrupt
Transform_Position_dZ/Transform_Scale_dZin theirRMTObjectrows. They self-heal one-by-one as their transforms are re-touched after the procedure is replaced. A batch heal — rebuilding the row z fields from the matrixd22/d23for affected sectors — could be done as a separate one-shotUPDATEif desired, but isn't required.