Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix race condition related to the measurement of PdfView #1

Merged
merged 2 commits into from
Dec 9, 2022

Conversation

j-piasecki
Copy link

It seems like in some cases, Yoga (I think) will measure the view only along one axis first, resulting in onSizeChanged being 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 to onSizeChanged with 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 PdfView in 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.onSizeChanged until the size in both dimensions is correct we are able to prevent this from happening.

//
// 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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move it up to the rest of private variables, also, can't we use oldw and oldh from the method?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can move them.

Since we're not calling super method every time, using oldw and oldh could result in inconsistencies: i.e.:

  • onSizeChanged gets called with w: 1080, h: 0, oldw: 0, oldh: 0
  • since h === 0, super.onSizeChanged doesn't get called
  • onSizeChanged gets called with w: 1080, h: 1600, oldw: 1080, oldh: 0
  • super.onSizeChanged gets called - if we were to use values from the arguments we would call it with oldw: 1080 where it wasn't called with w: 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.

@WoLewicki WoLewicki merged commit d7ba1bb into WoLewicki:@wolewicki/add-fabric Dec 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants