Mono, Glade and Images

Problem

When you are creating a new application using the great interface designer Glade, you possibly get some problems when using images.

Recently i have tried to port an application i have written in C, to C#. Since i have used Glade for all the interface design i have reused my .glade file for the C# application.

The problem i had with this application was the application icon i had set in Glade for this app. Glade only saves IMAGE.EXTENSION in the .glade XML file. Compiling the application just works fine but when executing the application (mono zynk.exe) i got a runtime error (view below).

The problem is, that the Mono runtime engine is trying to open an image that is not _existing_anywhere_. Shure it is, but Mono could not know where it is so you will have trouble with this.

Images will be included with a relative path to the .glade file and the Mono runtime engine will not find these files and this causes your application to crash.

Runtime Error

[hanez@phantom zynk#]$ gmcs -pkg:glade-sharp -resource:zynk.glade -resource:zynk.png zynk.cs

[hanez@phantom zynk#]$ mono zynk.exe

(:9122): GLib-CRITICAL **: g_path_get_dirname: assertion `file_name != NULL' failed

(:9122): GdkPixbuf-CRITICAL **: gdk_pixbuf_new_from_file: assertion `fi lename != NULL' failed

=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================

Stacktrace:

in <0x4> (wrapper managed-to-native) Glade.XML:glade_xml_new_from_buffer (byte[] ,int,string,string)
in <0xffffce9b> (wrapper managed-to-native) Glade.XML:glade_xml_new_from_buffer (byte[],int,string,string)
in <0xa3> Glade.XML:.ctor (System.Reflection.Assembly,string,string,string)
in <0x2c> ZynkApp:.ctor (string[])
in <0x19> ZynkApp:Main (string[])
in <0x7c84d27> (wrapper runtime-invoke) System.Object:runtime_invoke_void_string [] (object,intptr,intptr,intptr)

Native stacktrace:

        mono(mono_handle_native_sigsegv+0xba) [0x814c43a]
        mono [0x813890f]
        [0x842440]
        /usr/lib/libglade-2.0.so.0(glade_standard_build_widget+0x147) [0x3cee9ef ]
        /usr/lib/libglade/2.0/libgnome.so [0x4d2eb9]
        /usr/lib/libglade-2.0.so.0(glade_xml_build_widget+0x227) [0x3ceddba]
        /usr/lib/libglade-2.0.so.0 [0x3cedf71]
        /usr/lib/libglade-2.0.so.0(glade_xml_new_from_buffer+0x64) [0x3cee053]
        [0x4b7248]
        [0x4b4094]
        [0x4b3ca5]
        [0x4b3b92]
        [0x4b3ac3]
        mono [0x81387c0]
        mono(mono_runtime_invoke+0x27) [0x80d5067]
        mono(mono_runtime_exec_main+0x5c) [0x80d617c]
        mono(mono_runtime_run_main+0x171) [0x80d5da1]
        mono(strftime+0x1b52) [0x805ce52]
        mono(mono_main+0x786) [0x805d766]
        mono(__fxstat64+0x12b) [0x805c21b]
        /lib/libc.so.6(__libc_start_main+0xdf) [0x127d5f]
        mono(sinh+0x41) [0x805c171]
Aborted
[hanez@phantom zynk#]$

strace

open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/libgnomeui-2.0.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US.utf8/LC_MESSAGES/libgnomeui-2.0.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US/LC_MESSAGES/libgnomeui-2.0.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.UTF-8/LC_MESSAGES/libgnomeui-2.0.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.utf8/LC_MESSAGES/libgnomeui-2.0.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en/LC_MESSAGES/libgnomeui-2.0.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
write(2, "\n(:9218): GLib-CRITICAL"..., 94
(:9218): GLib-CRITICAL **: g_path_get_dirname: assertion `file_name != NULL' failed
) = 94
write(2, "\n(:9218): GdkPixbuf-CRI"..., 104
(:9218): GdkPixbuf-CRITICAL **: gdk_pixbuf_new_from_file: assertion `filename != NULL' failed
) = 104
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
write(2, "\n==============================="..., 292
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================

GDB

(no debugging symbols found)

(:9230): GLib-CRITICAL **: g_path_get_dirname: assertion `file_name != NULL' failed

(:9230): GdkPixbuf-CRITICAL **: gdk_pixbuf_new_from_file: assertion `filename != NULL' failed

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1273984 (LWP 9230)]
0x03ced258 in glade_xml_set_value_from_string () from /usr/lib/libglade-2.0.so.0
(gdb)

Solution

Don't use images directly in Glade when writing Mono / .NET applications. Set the application icon and similiar things in the sourcecode with the corresponding methods available in the Mono Gtk# / Glade# API.

The Glade property you not should use when writing Mono apps:

<property name="icon">zynk.png</property>

Thanks!

Since the problem is known since early 2005 allready, i have to thank Peter Johanson for his support in the #mono channel on IRC. He spent one hour of his life to help me figure that out... Thanks! ;)

Comments

Please enter your comment here:




Security check, please solve:

 5          EK1      
5M     S      7   S5I
 L    EHY   HQQ      
 9     1      I   B2Y
A73         N6B      

$Date: 2006-11-28 17:00:44 +0100 (Tue, 28 Nov 2006) $