[Glade-users] Error code



hello,

i'got trouble with an error code while running my own apps generated by
Glade. Everything worked fine until I programmed a drawing area inside
the main window. Here are the error codes:

Gdk-CRITICAL **: file gdkgc.c: line 456 (gdk_gc_set_foreground):
assertion 'gc != NULL' failed.
Gdk-CRITICAL **: file gdkdraw.c: line 89 (gdk_draw_rectangle) :
assertion 'drawable != NULL failed.
Gdk-CRITICAL **: file gdkdraw.c: line 380 (gdk_drw_pixmap) assertion
'src != NULL' failed

Here is the code I used It's this only file where the drawing area was
programmed and no compiling errors were returned. If anybody could help
me to see what wrong, it would be very nice

Thanks a lot

Valery Avaux

/*
 * Initial main.c file generated by Glade. Edit as required.
 * Glade will not overwrite this file.
 */

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <gtk/gtk.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include "interface.h"
#include "support.h"
#include "callbacks.h" 
#include <gdk/gdk.h>

/* variables globales du programme */
  int matrice[102][102][102],matrice2[102][102][102];
  long int hamilt1;
  long int nbsweep = 10000;
  int nbflip = 10;
  int genre = 1;
  long int interaction = 0;
  long int champ = 0;
  int tx = 10;
  int ty = 10;
  int tz = 10;
  float temp = 50.0;
  float field =0.; 
  GtkWidget *window1;

        GtkWidget *area;
GdkPixmap *pixmap = NULL;       /* offscreen drawable */
GdkGC *gc = NULL;
GdkColor blue;
GdkColor red;

void allocate_colors(GtkWidget *);
void repaint(GtkWidget *);
int  configure_event(GtkWidget *, GdkEventConfigure *);
int  expose_event(GtkWidget *, GdkEventExpose *);

int
main (int argc, char *argv[])
{
  GtkWidget *temper;
  GtkWidget *magnfield;
  GtkWidget *kind;


#ifdef ENABLE_NLS
  bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
  textdomain (PACKAGE);
#endif 

  gtk_set_locale ();
  gtk_init (&argc, &argv);

  add_pixmap_directory (PACKAGE_DATA_DIR "/pixmaps");
  add_pixmap_directory (PACKAGE_SOURCE_DIR "/pixmaps");

  initmat();

  window1 = create_window1 ();
  gtk_widget_show (window1);

  temper = lookup_widget (window1, "tempsc");
  magnfield = lookup_widget (window1, "hscale2");
  kind = lookup_widget (window1, "combo1");
  area = lookup_widget (window1, "drawingarea1");

  gtk_signal_connect (GTK_OBJECT (GTK_RANGE(temper) -> adjustment),
"value_changed", GTK_SIGNAL_FUNC ( on_tempsc_value_changed), temper);
  gtk_signal_connect (GTK_OBJECT (GTK_RANGE(magnfield) -> adjustment),
"value_changed", GTK_SIGNAL_FUNC (on_hscale2_value_changed),magnfield);
  gtk_signal_connect (GTK_OBJECT (GTK_COMBO(kind)-> entry),"activate",
GTK_SIGNAL_FUNC
  (on_combo_entry1_changed),NULL);
        gtk_signal_connect(GTK_OBJECT(area), "expose_event",
                           (GtkSignalFunc) expose_event, NULL);
        gtk_signal_connect(GTK_OBJECT(area), "configure_event",
                           (GtkSignalFunc) configure_event, NULL);

        repaint((GtkWidget *) area);
  gtk_main ();
  return 0;
}

/*
 *  init_colors  -  initialize the red and blue global variables
 */

void init_colors(GtkWidget *area)
{
        GdkColormap *colormap;

        colormap = gtk_widget_get_colormap(area);
        if (!colormap)
                exit(1);

        blue.red   = 0;
        blue.green = 0;
        blue.blue  = 0xff * 0x100;
        gdk_colormap_alloc_color(colormap, &blue, FALSE, TRUE);

        red.red   = 0xff * 0x100;
        red.green = 0;
        red.blue  = 0;
        gdk_colormap_alloc_color(colormap, &red, FALSE, TRUE);
}


/*
 *  repaint  -  redraws the contents of the matrix onto the
 *              offscreen drawable, and then copies that onto
 *              the drawing area
 */

void repaint(GtkWidget *area)
{
        int i, j;
        GdkColor *color;

        /*
         * update the offscreen drawable
         */

        for (i = 0; i < tx; i++)
                for (j = 0; j < ty; j++) {
                        color = (matrice[i][j][4] == 1) ? &red : &blue;
                        gdk_gc_set_foreground(gc, color);
                        gdk_draw_rectangle(pixmap, gc, TRUE,
                                           i * 4, j * 4, 4, 4);
                }

        /*
         * copy the offscreen drawable to the screen
         */

        gdk_draw_pixmap( area->window,
                         area->style->fg_gc[GTK_WIDGET_STATE(area)],
                         pixmap, 0, 0, 0, 0,
                         area->allocation.width, area->allocation.height );
}



/*
 *  configure_event  - called when the window is resized (and also the
 *                     when it is first created)
 *                   - creates the new backing pixmap of the appropriate
 *                     size, copies a white rectangle onto it as the
 *                     background, and calls repaint to draw the matrix
 */

int configure_event(GtkWidget *widget, GdkEventConfigure *event)
{
        if (!gc) {

                /*
                 *  This code is executed on the first configure event only,
                 *  i.e. when the window for the drawing area is created.
                 *  We create a new GC and allocate the colors we will use.
                 */
                gc = gdk_gc_new(widget->window);
                init_colors(widget);
        }

        if (pixmap)
                gdk_pixmap_unref(pixmap);

        pixmap = gdk_pixmap_new( widget->window,
                                 widget->allocation.width,
                                 widget->allocation.height,
                                 -1 );
        gdk_draw_rectangle( pixmap,
                            widget->style->white_gc,
                            TRUE, 0, 0,
                            widget->allocation.width,
                            widget->allocation.height );
        repaint(widget);
        return FALSE;
}




/*
 *  expose_event  -  called when the window is exposed to the viewer,
 *                   or the gdk_widget_draw routine is called
 *                -  copies the background pixmap to the window
 */

int expose_event(GtkWidget *widget, GdkEventExpose *event)
{
        gdk_draw_pixmap( widget->window,
                         widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
                         pixmap,
                         event->area.x, event->area.y,
                         event->area.x, event->area.y,
                         event->area.width, event->area.height );
        return FALSE;
}





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