You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While both Canvas and Surface implement AutoCloseable, when the GC hits, the Canvas is freed by its parent Surface (in the native lib) without marking the Canvas as closed. This causes a crash when doing anything with the orphaned Canvas object. It's most noticeable when resizing the window, since the whole thing gets thrown away (surface.close(); renderTarget.close()... unless I'm doing it wrong lol).
I believe when calling getCanvas() in Surface, the resulting Java object should be stored (cached) in the Surface object and returned with every subsequent call, and of course explicitly closed on cleanup.
I'd say that yes, that would be better, because there will be only one Canvas Java object for each Surface (more efficient -- memory, less native calls), and if it's freed by the parent Surface being collected, isClosed() will properly reflect that, instead of the current situation where only the parent Managed object reports "closed".
So all in all, more straightforward, efficient and obvious (_ptr set to 0 instead of some weird undefined behaviour with a dangling pointer).
While both Canvas and Surface implement AutoCloseable, when the GC hits, the Canvas is freed by its parent Surface (in the native lib) without marking the Canvas as closed. This causes a crash when doing anything with the orphaned Canvas object. It's most noticeable when resizing the window, since the whole thing gets thrown away (
surface.close(); renderTarget.close()
... unless I'm doing it wrong lol).I believe when calling
getCanvas()
in Surface, the resulting Java object should be stored (cached) in the Surface object and returned with every subsequent call, and of course explicitly closed on cleanup.Skija/shared/java/Surface.java
Lines 661 to 669 in a63330f
and possibly the opposite in Canvas where it should return its parent Surface (same as
_owner
).Skija/shared/java/Canvas.java
Lines 91 to 99 in a63330f
The text was updated successfully, but these errors were encountered: