Learner having problem with hello gtk eg

I have copied this example from the online docs:

using Gtk;

int main(string[] args) {
    Gtk.init(ref args);

    var window = new Window();
    window.title = "Hello Vala/Gtk";
    window.border_width = 10;
    window.window_position = WindowPosition.CENTER;
    window.set_default_size(350, 70);
    window.destroy.connect(Gtk.main_quit);
    try {
	window.icon = new Gdk.Pixbuf.from_file("images/icon.png");
    } catch (Error err) {
	stderr.printf("failed to load icon: %s\n", err.message); // Happens on Windows only
    }

    var button = new Button.with_label("Click me!");
    button.clicked.connect(() => {
        button.label = "Thank you:-)";
    });

    window.add(button);
    window.show_all();

    Gtk.main();
    return 0;
}

I have created an images subdir with an icon.png image and an icon.ico image.
I build the app using: valac -o hellogtk --pkg gtk+-3.0 hellogtk.vala which works on both Linux and Windows.
The app runs on both Linux and Windows.
However, on Windows (MSYS2) the error message about the icon is output. I tried changing to the icon.ico but that didn’t help. I can always set the icon using a resource editor but am curious about this platform difference.

1 Like

The question I’d ask first is what is the error message? There could be multiple reasons why it fails, either related to the platform itself (windows not liking the slash in the path, expecting a backslash instead?) or to the way gtk and its dependencies have been built (MSYS2 not building support for png? I don’t think that would happen but it may)

Sorry, I forgot to include it:

failed to load icon: CouldnΓÇÖt recognize the image file format for file ΓÇ£images/icon.pngΓÇ¥

As you can see there is an encoding problem in the MSYS2 terminal. I’ve tried various ones but none seem to work.
I got the same problem with an icon.ico file.
Could it be that I need to install additional image-related libraries for Gtk to use?

Further to this I copied this example: https://github.com/vala-lang/valadoc-org/blob/master/examples/gtk%2B-3.0/Gtk.Viewport.vala
On Linux it worked fine and showed .png and .svg images.
On Windows it crashes:

$ viewport.exe ../hellogtk/images/icon.png

(viewport.exe:3048): Gtk-WARNING **: 11:25:49.875: Could not load a pixbuf from /org/gtk/libgtk/icons/16x16/status/image-missing.png.
This may indicate that pixbuf loaders or the mime database could not be found.
**
Gtk:ERROR:../gtk+-3.24.20/gtk/gtkiconhelper.c:494:ensure_surface_for_gicon: assertion failed (error == NULL): Failed to load /org/gtk/libgtk/icons/16x16/status/image-missing.png: Unrecognized image file format (gdk-pixbuf-error-quark, 3)
Bail out! Gtk:ERROR:../gtk+-3.24.20/gtk/gtkiconhelper.c:494:ensure_surface_for_gicon: assertion failed (error == NULL): Failed to load /org/gtk/libgtk/icons/16x16/status/image-missing.png: Unrecognized image file format (gdk-pixbuf-error-quark, 3)

I also tried this example: https://github.com/vala-lang/valadoc-org/blob/master/examples/gtk%2B-3.0/Gtk.IconView.vala
And again it works fine on Linux but crashes on Windows:

$ iconview.exe

(iconview.exe:2052): Gtk-WARNING **: 11:29:28.250: Could not find the icon 'help-about'. The 'hicolor' theme
was not found either, perhaps you need to install it.
You can get a copy from:
        http://icon-theme.freedesktop.org/releases
**
ERROR:C:/bin/msys64/home/mark/vala/learn/iconview/iconview.vala.c:334:application_construct: code should not be reached
Bail out! ERROR:C:/bin/msys64/home/mark/vala/learn/iconview/iconview.vala.c:334:application_construct: code should not be reached

Here’re the packages I’ve installed in MSYS2:

$ pacman -Qe
base 2020.05-2
filesystem 2020.02-5
mingw-w64-x86_64-gcc 10.1.0-3
mingw-w64-x86_64-gtk3 3.24.20-3
mingw-w64-x86_64-libgee 0.20.3-1
mingw-w64-x86_64-pkg-config 0.29.2-1
mingw-w64-x86_64-vala 0.48.7-1
vim 8.2.0869-1

What am I missing or doing wrong?

I suspect that you have some leftover binaries in your path from older installations. Open the MSYS2 mingw64 console and type:

which gdk-pixbuf-query-loaders

What’s the output?

I don’t have any older MSYS2 installations, I did a fresh install specifically for Vala as per the Vals fo Windows installation instructions:

$ which gdk-pixbuf-query-loaders
/mingw64/bin/gdk-pixbuf-query-loaders

FYI I’m testing on two VirtualBox Win 7 64-bit installations.

Ok. Could you then launch:

gdk-pixbuf-query-loaders

And post here the output?
After that, launch:

gdk-pixbuf-query-loaders --update-cache

That hopefully should fix any problem with the loading modules

Here’s the output requested:

$ gdk-pixbuf-query-loaders
# GdkPixbuf Image Loader Modules file
# Automatically generated file, do not edit
# Created by gdk-pixbuf-query-loaders from gdk-pixbuf-2.40.0
#
# LoaderDir = C:\bin\msys64\mingw64\lib\gdk-pixbuf-2.0\2.10.0\loaders
#
"lib\\gdk-pixbuf-2.0\\2.10.0\\loaders\\libpixbufloader-ani.dll"
"ani" 4 "gdk-pixbuf" "Windows animated cursor" "LGPL"
"application/x-navi-animation" ""
"ani" ""
"RIFF    ACON" "    xxxx    " 100

"lib\\gdk-pixbuf-2.0\\2.10.0\\loaders\\libpixbufloader-bmp.dll"
"bmp" 5 "gdk-pixbuf" "BMP" "LGPL"
"image/bmp" "image/x-bmp" "image/x-MS-bmp" ""
"bmp" ""
"BM" "" 100

"lib\\gdk-pixbuf-2.0\\2.10.0\\loaders\\libpixbufloader-gif.dll"
"gif" 4 "gdk-pixbuf" "GIF" "LGPL"
"image/gif" ""
"gif" ""
"GIF8" "" 100

"lib\\gdk-pixbuf-2.0\\2.10.0\\loaders\\libpixbufloader-icns.dll"
"icns" 4 "gdk-pixbuf" "MacOS X icon" "GPL"
"image/x-icns" ""
"icns" ""
"icns" "" 100

"lib\\gdk-pixbuf-2.0\\2.10.0\\loaders\\libpixbufloader-ico.dll"
"ico" 5 "gdk-pixbuf" "Windows icon" "LGPL"
"image/x-icon" "image/x-ico" "image/x-win-bitmap" "image/vnd.microsoft.icon" "application/ico" "image/ico" "image/icon" "text/ico" ""
"ico" "cur" ""
"  \001   " "zz znz" 100
"  \002   " "zz znz" 100

"lib\\gdk-pixbuf-2.0\\2.10.0\\loaders\\libpixbufloader-jasper.dll"
"jpeg2000" 4 "gdk-pixbuf" "JPEG 2000" "LGPL"
"image/jp2" "image/jpeg2000" "image/jpx" ""
"jp2" "jpc" "jpx" "j2k" "jpf" ""
"    jP" "!!!!  " 100
"\377O\377Q" "" 100

"lib\\gdk-pixbuf-2.0\\2.10.0\\loaders\\libpixbufloader-jpeg.dll"
"jpeg" 5 "gdk-pixbuf" "JPEG" "LGPL"
"image/jpeg" ""
"jpeg" "jpe" "jpg" ""
"\377\330" "" 100

"lib\\gdk-pixbuf-2.0\\2.10.0\\loaders\\libpixbufloader-png.dll"
"png" 5 "gdk-pixbuf" "PNG" "LGPL"
"image/png" ""
"png" ""
"\211PNG\r\n\032\n" "" 100

"lib\\gdk-pixbuf-2.0\\2.10.0\\loaders\\libpixbufloader-pnm.dll"
"pnm" 4 "gdk-pixbuf" "PNM/PBM/PGM/PPM" "LGPL"
"image/x-portable-anymap" "image/x-portable-bitmap" "image/x-portable-graymap" "image/x-portable-pixmap" ""
"pnm" "pbm" "pgm" "ppm" ""
"P1" "" 100
"P2" "" 100
"P3" "" 100
"P4" "" 100
"P5" "" 100
"P6" "" 100

"lib\\gdk-pixbuf-2.0\\2.10.0\\loaders\\libpixbufloader-qtif.dll"
"qtif" 4 "gdk-pixbuf" "QuickTime" "LGPL"
"image/x-quicktime" "image/qtif" ""
"qtif" "qif" ""
"abcdidsc" "xxxx    " 100
"abcdidat" "xxxx    " 100

"lib\\gdk-pixbuf-2.0\\2.10.0\\loaders\\libpixbufloader-svg.dll"
"svg" 6 "gdk-pixbuf" "Scalable Vector Graphics" "LGPL"
"image/svg+xml" "image/svg" "image/svg-xml" "image/vnd.adobe.svg+xml" "text/xml-svg" "image/svg+xml-compressed" ""
"svg" "svgz" "svg.gz" ""
" <svg" "*    " 100
" <!DOCTYPE svg" "*             " 100

"lib\\gdk-pixbuf-2.0\\2.10.0\\loaders\\libpixbufloader-tga.dll"
"tga" 4 "gdk-pixbuf" "Targa" "LGPL"
"image/x-tga" ""
"tga" "targa" ""
" \001\001" "x  " 100
" \001\t" "x  " 100
"  \002" "xz " 99
"  \003" "xz " 100
"  \n" "xz " 100
"  \v" "xz " 100

"lib\\gdk-pixbuf-2.0\\2.10.0\\loaders\\libpixbufloader-tiff.dll"
"tiff" 5 "gdk-pixbuf" "TIFF" "LGPL"
"image/tiff" ""
"tiff" "tif" ""
"MM *" "  z " 100
"II* " "   z" 100
"II* \020   CR\002 " "   z zzz   z" 0

"lib\\gdk-pixbuf-2.0\\2.10.0\\loaders\\libpixbufloader-xbm.dll"
"xbm" 4 "gdk-pixbuf" "XBM" "LGPL"
"image/x-xbitmap" ""
"xbm" ""
"#define " "" 100
"/*" "" 50

"lib\\gdk-pixbuf-2.0\\2.10.0\\loaders\\libpixbufloader-xpm.dll"
"xpm" 4 "gdk-pixbuf" "XPM" "LGPL"
"image/x-xpixmap" ""
"xpm" ""
"/* XPM */" "" 100

I then ran gdk-pixbuf-query-loaders --update-cache as suggested.

Unfortunately this didn’t help: I still get the same problems. hellogtk runs but produces the error output, and viewport and iconview both give the same error messages as before.

Whot, that’s really strange!..
What happens with:

gtk3-icon-browser

Shouldn’t that run, try:

gtk-update-icon-cache -f
gtk-update-icon-cache --validate

Hope it helps :wink: let me know

gtk3-icon-browser works fine! I clicked most of the categories and they all showed icons and there was no error output at all.

$ gtk-update-icon-cache -f

(gtk-update-icon-cache.exe:2024): GLib-CRITICAL **: 11:54:11.863: g_convert: assertion 'str != NULL' failed
gtk-update-icon-cache.exe: No theme index file in '(NULL)'.
If you really want to create an icon cache here, use --ignore-theme-index.

$ gtk-update-icon-cache --validate

(gtk-update-icon-cache.exe:2320): GLib-CRITICAL **: 11:56:18.394: g_convert: assertion 'str != NULL' failed
gtk-update-icon-cache.exe: File not found:

And the icon browser still works fine.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.