Re: Simple GDK app segfaults for unknown reason



Hey Gyözö,

On Fri, 2006-01-20 at 18:24 +0100, Gyözö Both wrote:
hi,

i'd say you forgot to end the call with a NULL. also, as far as i know
the standard way to use GError is to have a 'GError *error;' variable
and then pass the pointer to it. in your case:

GError *error = NULL;
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file("input.jpg", &error);
gdk_pixbuf_save(pixbuf, "output.bmp", "bmp", &error, NULL);

It turned out that the problem really was that I didn't end the
gdk_pixbuf_save() call with a NULL.

I also realize that I incorrectly used GError, although in this case it
didn't cause any errors.

but of course it doesn't make sense to use GError if you don't look at
the error variable afterwards; e.g. to display the error message if
there was an error and free the error variable with g_error_free. i use
in my projects a function to check GErrors (called every time i used a
function that i passed a GError to):

/**
   Print the contents of a GError (if it was set).
   If abort_program is TRUE, we free the memory
   and exit the game.
   @param error The GError we check.
   @param abort_program Whether or not we continue or exit the program.
*/
void
misc_print_error(GError **error, gboolean abort_program)
{
    if(*error == NULL)
        return;
    
    g_warning("error message: %s\n", (*error)->message);
    g_error_free(*error);
    *error = NULL;

    if(abort_program)
        main_exit_program(EXIT_PRINT_ERROR, NULL);
}

Looks cool.  I'll use your function.

i hope i could help.

Absolutely!

Thanks everyone for the help!  This is one the most helpful communities
I've ever came across.

-- 
Laci

    Blog: http://monda.hu/~laci/blog
    Home: http://mondalaci.objectis.net





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]