B4J Question Memory issue: picture zoom, error "Cannot invoke "com.sun.prism.RTTexture.createGraphics()" because "<local9>" is null"

peacemaker

Expert
Licensed User
Longtime User
Hi, All

If to make zooming a picture in - i have the non-fatal error:
java.lang.NullPointerException: Cannot invoke "com.sun.prism.RTTexture.createGraphics()" because "<local9>" is null
The point of the error is unknown (seems, in the JavaFX internal code) - it cannot be caught.
The interface is hung, this error is generated one by one, but if to zoom back out - it can be normalized.
It looks like the limit is around 4.3 times for my test picture enlarging. For smaller picture it can be OK upto 7.5 times.

There is some explanation: https://stackoverflow.com/questions/65565209/nullpointers-in-javafx-when-using-a-large-canvas
But how to detect it and prevent on time ? Now i do not zoom after 4.0 ratio. But it needs to check by the memory, i think, that depends on the picture size and PC RAM.
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
As temporarily solution, such calculations:
B4X:
    If ZoomDelta > 1 Then
        Dim ZoomRatio As Float = ImageView.Width * ImageView.Height / InitialArea  'bitmap area at initial loading
        Log("ZoomRatio = " & ZoomRatio)
        Dim CalcRatio As Float = 598437 / InitialArea * 4 / 1.5
        Log("CalcRatio = " & CalcRatio)
        If ZoomRatio >= CalcRatio Then    '4 for 598437 pixels of bmp area - my test on my PC
            Log("Zoom is limited by the memory, ZoomRatio = " & ZoomRatio)
            Return
        End If
    End If
    'next - zooming:....
 
Upvote 0
Top