Trying to load a gtk image from a resource causes the JVM to crash #314

Closed
opened 2025-12-23 21:49:29 +01:00 by andreibachim · 3 comments
andreibachim commented 2025-12-23 21:49:29 +01:00 (Migrated from github.com)

Hi,

There seems to be something wrong with how images are loaded from resources.

I have a compiled gresource file that includes to a valid .svg file. I can see the file when exploring the Resource object using enumerateChildren method on the Resource objects. However, if I try to instantiate a gtk image object from said resource, the JVM crashes.

Another possible related issue could be that the application-icon property of the AboutDialog also cannot display said icon. It doesn't crash, it just does not load the icon.

Here is a snippet of the crash log with the stack trace.

Stack: [0x00007fa1a5300000,0x00007fa1a5400000],  sp=0x00007fa1a53fc650,  free space=1009k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [libgtk-4.so.1+0x274304]
C  [libgtk-4.so.1+0x288d65]
C  [libgtk-4.so.1+0x28a5a1]
C  [libgtk-4.so.1+0x28a6e5]
C  [libgtk-4.so.1+0x26e6e7]
C  [libgobject-2.0.so.0+0x33357]  g_type_create_instance+0x247
C  [libgobject-2.0.so.0+0x188a4]
C  [libgobject-2.0.so.0+0x19ec7]  g_object_new_with_properties+0x227
C  [libgobject-2.0.so.0+0x1aea1]  g_object_new+0xc1
C  [libgtk-4.so.1+0x1ff607]
C  [libgobject-2.0.so.0+0x33357]  g_type_create_instance+0x247
C  [libgobject-2.0.so.0+0x188a4]
C  [libgobject-2.0.so.0+0x19ec7]  g_object_new_with_properties+0x227
C  [libgobject-2.0.so.0+0x1aea1]  g_object_new+0xc1
C  [libgtk-4.so.1+0xdefe1]  gtk_image_new_from_resource+0x21
v  ~RuntimeStub::nep_invoker_blob 0x00007fa18fcc119e
j  java.lang.invoke.LambdaForm$MH+0x000000004f107400.invoke(Ljava/lang/Object;JJ)J+10 java.base@25.0.1
j  java.lang.invoke.LambdaForm$MH+0x000000004f3a3c00.invokeExact_MT(Ljava/lang/Object;JJLjava/lang/Object;)J+21 java.base@25.0.1
j  jdk.internal.foreign.abi.DowncallStub+0x000000004f107800.invoke(Ljava/lang/foreign/SegmentAllocator;Ljava/lang/foreign/MemorySegment;Ljava/lang/foreign/MemorySegment;)Ljava/lang/foreign/MemorySegment;+70 java.base@25.0.1
j  java.lang.invoke.LambdaForm$DMH+0x000000004f107c00.invokeStaticInit(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;+14 java.base@25.0.1
j  java.lang.invoke.LambdaForm$MH+0x000000004f108c00.invoke(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;+44 java.base@25.0.1
j  java.lang.invoke.Invokers$Holder.invokeExact_MT(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;+19 java.base@25.0.1
j  org.gnome.gtk.Image.constructFromResource(Ljava/lang/String;)Ljava/lang/foreign/MemorySegment;+22
j  org.gnome.gtk.Image.fromResource(Ljava/lang/String;)Lorg/gnome/gtk/Image;+1
j  org.codeberg.beebanoo.shortcut.Main.main([Ljava/lang/String;)V+15
v  ~StubRoutines::call_stub 0x00007fa18fa5ffa6
V  [libjvm.so+0x9f1220]  JavaCalls::call_helper(JavaValue*, methodHandle const&, JavaCallArguments*, JavaThread*)+0x2b0
V  [libjvm.so+0xab8fa6]  jni_invoke_static(JNIEnv_*, JavaValue*, _jobject*, JNICallType, _jmethodID*, JNI_ArgumentPusher*, JavaThread*) [clone .constprop.1]+0x376
V  [libjvm.so+0xabb88c]  jni_CallStaticVoidMethod+0x13c
C  [libjli.so+0x3b3a]  invokeStaticMainWithArgs+0x4a
C  [libjli.so+0x4bc0]  JavaMain+0xeb0
C  [libjli.so+0x8149]  ThreadJavaMain+0x9
C  [libc.so.6+0x72464]  start_thread+0x2e4
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
v  ~RuntimeStub::nep_invoker_blob 0x00007fa18fcc1168
j  java.lang.invoke.LambdaForm$MH+0x000000004f107400.invoke(Ljava/lang/Object;JJ)J+10 java.base@25.0.1
j  java.lang.invoke.LambdaForm$MH+0x000000004f3a3c00.invokeExact_MT(Ljava/lang/Object;JJLjava/lang/Object;)J+21 java.base@25.0.1
j  jdk.internal.foreign.abi.DowncallStub+0x000000004f107800.invoke(Ljava/lang/foreign/SegmentAllocator;Ljava/lang/foreign/MemorySegment;Ljava/lang/foreign/MemorySegment;)Ljava/lang/foreign/MemorySegment;+70 java.base@25.0.1
j  java.lang.invoke.LambdaForm$DMH+0x000000004f107c00.invokeStaticInit(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;+14 java.base@25.0.1
j  java.lang.invoke.LambdaForm$MH+0x000000004f108c00.invoke(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;+44 java.base@25.0.1
j  java.lang.invoke.Invokers$Holder.invokeExact_MT(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;+19 java.base@25.0.1
j  org.gnome.gtk.Image.constructFromResource(Ljava/lang/String;)Ljava/lang/foreign/MemorySegment;+22
j  org.gnome.gtk.Image.fromResource(Ljava/lang/String;)Lorg/gnome/gtk/Image;+1
j  org.codeberg.beebanoo.shortcut.Main.main([Ljava/lang/String;)V+15
v  ~StubRoutines::call_stub 0x00007fa18fa5ffa6
Hi, There seems to be something wrong with how images are loaded from resources. I have a compiled gresource file that includes to a valid `.svg` file. I can see the file when exploring the Resource object using `enumerateChildren` method on the `Resource` objects. However, if I try to instantiate a gtk image object from said resource, the JVM crashes. Another possible related issue could be that the `application-icon` property of the AboutDialog also cannot display said icon. It doesn't crash, it just does not load the icon. Here is a snippet of the crash log with the stack trace. ```java Stack: [0x00007fa1a5300000,0x00007fa1a5400000], sp=0x00007fa1a53fc650, free space=1009k Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) C [libgtk-4.so.1+0x274304] C [libgtk-4.so.1+0x288d65] C [libgtk-4.so.1+0x28a5a1] C [libgtk-4.so.1+0x28a6e5] C [libgtk-4.so.1+0x26e6e7] C [libgobject-2.0.so.0+0x33357] g_type_create_instance+0x247 C [libgobject-2.0.so.0+0x188a4] C [libgobject-2.0.so.0+0x19ec7] g_object_new_with_properties+0x227 C [libgobject-2.0.so.0+0x1aea1] g_object_new+0xc1 C [libgtk-4.so.1+0x1ff607] C [libgobject-2.0.so.0+0x33357] g_type_create_instance+0x247 C [libgobject-2.0.so.0+0x188a4] C [libgobject-2.0.so.0+0x19ec7] g_object_new_with_properties+0x227 C [libgobject-2.0.so.0+0x1aea1] g_object_new+0xc1 C [libgtk-4.so.1+0xdefe1] gtk_image_new_from_resource+0x21 v ~RuntimeStub::nep_invoker_blob 0x00007fa18fcc119e j java.lang.invoke.LambdaForm$MH+0x000000004f107400.invoke(Ljava/lang/Object;JJ)J+10 java.base@25.0.1 j java.lang.invoke.LambdaForm$MH+0x000000004f3a3c00.invokeExact_MT(Ljava/lang/Object;JJLjava/lang/Object;)J+21 java.base@25.0.1 j jdk.internal.foreign.abi.DowncallStub+0x000000004f107800.invoke(Ljava/lang/foreign/SegmentAllocator;Ljava/lang/foreign/MemorySegment;Ljava/lang/foreign/MemorySegment;)Ljava/lang/foreign/MemorySegment;+70 java.base@25.0.1 j java.lang.invoke.LambdaForm$DMH+0x000000004f107c00.invokeStaticInit(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;+14 java.base@25.0.1 j java.lang.invoke.LambdaForm$MH+0x000000004f108c00.invoke(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;+44 java.base@25.0.1 j java.lang.invoke.Invokers$Holder.invokeExact_MT(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;+19 java.base@25.0.1 j org.gnome.gtk.Image.constructFromResource(Ljava/lang/String;)Ljava/lang/foreign/MemorySegment;+22 j org.gnome.gtk.Image.fromResource(Ljava/lang/String;)Lorg/gnome/gtk/Image;+1 j org.codeberg.beebanoo.shortcut.Main.main([Ljava/lang/String;)V+15 v ~StubRoutines::call_stub 0x00007fa18fa5ffa6 V [libjvm.so+0x9f1220] JavaCalls::call_helper(JavaValue*, methodHandle const&, JavaCallArguments*, JavaThread*)+0x2b0 V [libjvm.so+0xab8fa6] jni_invoke_static(JNIEnv_*, JavaValue*, _jobject*, JNICallType, _jmethodID*, JNI_ArgumentPusher*, JavaThread*) [clone .constprop.1]+0x376 V [libjvm.so+0xabb88c] jni_CallStaticVoidMethod+0x13c C [libjli.so+0x3b3a] invokeStaticMainWithArgs+0x4a C [libjli.so+0x4bc0] JavaMain+0xeb0 C [libjli.so+0x8149] ThreadJavaMain+0x9 C [libc.so.6+0x72464] start_thread+0x2e4 Java frames: (J=compiled Java code, j=interpreted, Vv=VM code) v ~RuntimeStub::nep_invoker_blob 0x00007fa18fcc1168 j java.lang.invoke.LambdaForm$MH+0x000000004f107400.invoke(Ljava/lang/Object;JJ)J+10 java.base@25.0.1 j java.lang.invoke.LambdaForm$MH+0x000000004f3a3c00.invokeExact_MT(Ljava/lang/Object;JJLjava/lang/Object;)J+21 java.base@25.0.1 j jdk.internal.foreign.abi.DowncallStub+0x000000004f107800.invoke(Ljava/lang/foreign/SegmentAllocator;Ljava/lang/foreign/MemorySegment;Ljava/lang/foreign/MemorySegment;)Ljava/lang/foreign/MemorySegment;+70 java.base@25.0.1 j java.lang.invoke.LambdaForm$DMH+0x000000004f107c00.invokeStaticInit(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;+14 java.base@25.0.1 j java.lang.invoke.LambdaForm$MH+0x000000004f108c00.invoke(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;+44 java.base@25.0.1 j java.lang.invoke.Invokers$Holder.invokeExact_MT(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;+19 java.base@25.0.1 j org.gnome.gtk.Image.constructFromResource(Ljava/lang/String;)Ljava/lang/foreign/MemorySegment;+22 j org.gnome.gtk.Image.fromResource(Ljava/lang/String;)Lorg/gnome/gtk/Image;+1 j org.codeberg.beebanoo.shortcut.Main.main([Ljava/lang/String;)V+15 v ~StubRoutines::call_stub 0x00007fa18fa5ffa6 ```
jwharm commented 2025-12-23 21:53:29 +01:00 (Migrated from github.com)

Does the crash happen with any svg file, or only with a specific one? If so, can you please attach it to the issue?

Does the crash happen with any svg file, or only with a specific one? If so, can you please attach it to the issue?
andreibachim commented 2025-12-23 22:23:28 +01:00 (Migrated from github.com)

Oh, I think it's a user problem. I was trying to load the image before calling run() on the application, so GTK was not initialized. If I load the image after that, it is fine.

You can reproduce the issue on this fork of the app template project if you still want to see it.

Oh, I think it's a user problem. I was trying to load the image before calling run() on the application, so GTK was not initialized. If I load the image after that, it is fine. You can reproduce the issue on this fork of the [app template project](https://github.com/andreibachim/java-gi-app-template#) if you still want to see it.
jwharm commented 2025-12-23 22:38:39 +01:00 (Migrated from github.com)

OK, makes sense.

OK, makes sense.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
java-gi/java-gi#314
No description provided.