Open harbulot opened 9 months ago
Thanks for the report @harbulot!
I know you stated in the first sentence that you were unable to make a code demo of the issue, but just being perfectly honest without a demo, it could be a while before I am able to dedicate the time to investigate and fix. Alternatively you're more than welcome to open a PR if you've got a clean solution that will not negatively impact other user's use cases!
This is using Androidplot 1.5.10.
Due to various degrees of nesting (e.g. XYPlot within a LinearLayout, within a fragment that replaces a FrameLayout of the fragment of a ViewPager2's page, ...), I've encountered a situation where the one of the dimensions of the XYPlot instance is 0, before being expended to its actual size later on. (Apologies, I'm unable to re-create a small fully contained example.)
In this case,
renderOnCanvas
is called with anull
Canvas
, but when we're using a background thread,isIdle
is never set totrue
in this case (as it would with non-zero dimensions). As a result, the background thread is stuck waiting atrenderSync.wait()
, and the plot can never be rendered by resizing.Details
In a situation where rendering is done in background-thread mode, this shows these logs:
The problem here is that the background thread, and the first pass at rendering starts with a dimension of 0 height.
In this case, the
Canvas
in thepingPong
instance isnull
, inPlot.startBackgroundrendering()
.Indeed, the
BufferedCanvas
is resized using(0,0)
, which makes itsbgBuffer
null
, and therefore makesgetCanvas()
returnnull
.As a result,
renderOnCanvas
returns straight away:The problem here, is that
isIdle
is never set to true (as it would with a non-null canvas).As a result,
redraw()
never does anything, sinceisIdle
is alwaysfalse
:Because of that,
renderSync.notify()
can never be called, so the background thread is stuck atrenderSync.wait()
, so no further redrawing can take place.Solution
Setting
isIdle = true
inPlot.renderOnCanvas
seems to fix the problem: