Login  Register

I had a fun one today.

classic Classic list List threaded Threaded
3 messages Options Options
Embed post
Permalink
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

I had a fun one today.

imakerobots
59 posts
For reasons I won't go into, I had to make a Graphics2D wrapper for GL2.  the wrapper dispose() calls gl2.glEnd().
I manually call dispose() because I clean up after myself.  Ran fine here, passed all tests.

Two days after release a client says it crashes within seconds of startup.  No log incident generated, even when I threw an exception in dispose().  Eventually we got a FATAL EXCEPTION on the command line.  Turns out the garbage cleaner is calling finalize() which calls glEnd() which then dies because something inside gl2 is probably null?  points to 0x00000000.

I can't reproduce it in a test case but I thought I'd share it anyhow.  Maybe there's a way to test calling glEnd() twice to see if it warns, exceptions, or dies in the native driver.

hs_err_pid5072.log
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: I had a fun one today.

gouessej
Administrator
6035 posts
This post was updated on Mar 26, 2025; 8:57am.
Hello

dispose() is probably called on the wrong thread (not the one that was used to create the OpenGL context) or when the context isn't current. Maybe dispose() isn't safe to be called twice. Why do you need to call dispose() manually? What is Graphics2DGL exactly?

P.S: Relying on finalization is a bad idea anyway as finalize() is deprecated since Java 18.

P.S 2: Maybe a solution would consist in avoiding to call dispose() manually and performing a more narrow cleaning.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: I had a fun one today.

imakerobots
59 posts
https://docs.oracle.com/javase/8/docs/api/java/awt/Graphics.html#dispose--

> it is preferable to manually free the associated resources by calling this method rather than to rely on a finalization process

I didn't expect finalize() to be called, it's on by default in IntelliJ running JDK 22, so I wrote code to handle either way.