Fix race condition related to the measurement of PdfView#1
Merged
WoLewicki merged 2 commits intoWoLewicki:@wolewicki/add-fabricfrom Dec 9, 2022
Merged
Fix race condition related to the measurement of PdfView#1WoLewicki merged 2 commits intoWoLewicki:@wolewicki/add-fabricfrom
PdfView#1WoLewicki merged 2 commits intoWoLewicki:@wolewicki/add-fabricfrom
Conversation
WoLewicki
reviewed
Dec 9, 2022
| // | ||
| // I'm not sure whether the second condition is necessary, but without it, it would be impossible | ||
| // to set the dimensions to zero after first measurement. | ||
| private int oldW = 0, oldH = 0; |
Owner
There was a problem hiding this comment.
I'd move it up to the rest of private variables, also, can't we use oldw and oldh from the method?
Author
There was a problem hiding this comment.
Sure, I can move them.
Since we're not calling super method every time, using oldw and oldh could result in inconsistencies: i.e.:
onSizeChangedgets called withw: 1080, h: 0, oldw: 0, oldh: 0- since
h === 0,super.onSizeChangeddoesn't get called onSizeChangedgets called withw: 1080, h: 1600, oldw: 1080, oldh: 0super.onSizeChangedgets called - if we were to use values from the arguments we would call it witholdw: 1080where it wasn't called withw: 1080
I haven't looked that deep to see whether it's actually used anywhere, but since those params are there I guess they are used somewhere.
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.
It seems like in some cases, Yoga (I think) will measure the view only along one axis first, resulting in
onSizeChangedbeing called with either w or h set to zero. This in turn starts the rendering of the pdf under the hood with one dimension being set to zero and the follow-up call toonSizeChangedwith the correct dimensions doesn't have any effect on the already started process.The offending class is DecodingAsyncTask, which tries to get width and height of the
PdfViewin the constructor, and is created as soon as the measurement is complete (relevant lines here and here), which in some cases may be incomplete as described above.By delaying calling
super.onSizeChangeduntil the size in both dimensions is correct we are able to prevent this from happening.