fix: incorrect cache validation logic causing cache false hit - #1965
Open
MaksimGalois wants to merge 1 commit into
Open
fix: incorrect cache validation logic causing cache false hit#1965MaksimGalois wants to merge 1 commit into
MaksimGalois wants to merge 1 commit into
Summary
In
YGLayout.cpp, when callingnewSizeIsStricterAndStillValidto check measure cache eligibility, the current constraintsizeis passed as net remaining space (availableHeight - marginColumn). However, the historical constraintlastSizeis erroneously passed as gross space (lastAvailableHeight) without subtracting the margin.This asymmetric comparison (comparing net space with gross space) leads Yoga to falsely assume that the available space has shrunk (triggering the
lastSize > sizebranch) when the container actually grows. Consequently, a truncated cache result from a previously compressed pass is incorrectly reused.Solution
Deduct the corresponding margin size (
marginColumn/marginRow) fromlastAvailableHeight/lastAvailableWidthrespectively when callingnewSizeIsStricterAndStillValidto ensure symmetrical net-to-net boundary comparisons.Changelog
[C++] [Fixed] - Correct net layout space comparison in measure cache check by deducting margin.
Test Plan & Minimal Reproducible Example
Added a new dedicated unit test
remeasure_when_container_grows_with_child_margininYGMeasureCacheTest.cpp, which serves as a MRE for this specific bug.Reproduction and Verification Steps:
10.0f). Due to a child margin (5.0f), the net available space for the child is constrained to5.0f. The child's measured layout height is compressed to5.0fand cached erroneously.15.0f, releasing enough net available space (10.0f) to completely accommodate the child's desired target height (10.0f).newSizeIsStricterAndStillValid, Yoga incorrectly triggers a false cache hit during the second pass. It blindly reuses the stale, compressed height of5.0ffrom the cache without re-measuring, causing themeasureCountassertion to fail (retains 1 instead of 2).measureCountincrements to 2) and the child layout height successfully recovers to its correct desired height of10.0f. All assertions pass green.