error in passing a structure in argument of a CallBack function



hello
 
could someone tell me where is the error when I am passing a structure in argument of  a Callback function as gpointer data ;
I have no warning and error at the compilation ..

Thank you a lot for  help

Dominique Reymond

 

here is the code:

/////////////////////////////////////////////////////////////////////////////////

/* the structure to be transfered */
struct stab {
    int npt;                        /* numbero f point of the array */
    float *tx;                     /* an array of float */
    GtkWidget *label;
};

/* the function prototype */
gboolean CallBackRedraw(GtkWidget *zone_dessin, GdkEventExpose *ev, gpointer data );

int main(void)
{
 ....
}
/*********************************/
void function_1(void)
{
..........

 struct stab psTab;

 psTab = (struct stab *)g_malloc(sizeof(struct stab *));
 if ( psTab == NULL ) { printf(" pb to alloc struct \n"); exit(-1); }

 psTab->npt = 1000;

 psTab->tx = (float *)g_malloc0(psTab->npt * sizeof(float));
 if ( psTab->tx == NULL ) { printf(" pb to alloc array\n"); exit(-1); }

/*
...
some code to fill the array psTab->tx
....
*/

/* no problem until this point: everything is OK */
 printf("adr. struct: %x       npt: %d  psTab->tx[0]%f \n",
                            psTab,
                            psTab->npt,
                            psTab->tx[0]);

 // redraw the window with expose event
// here start the problem

   gtk_signal_connect(GTK_OBJECT(ZoneFourier),
                                        "expose_event",
                                          GTK_SIGNAL_FUNC(CallBackRedraw),
                                          (gpointer)psTab);

............
...............
 free( psTab->tx);
 free( psTab);

}
/******************************************************************/
gboolean CallBackRedraw(GtkWidget *zone_dessin, GdkEventExpose *ev,  gpointer data )
{

  GdkColor gdk_color;
  GdkColormap *Colormap_Fourier;
  GdkGC *gc_Fourier;
  struct stab *sz;
  int i;

  sz = (struct stab *)data;

printf("adr. struct: %x   npt: %d SZ->tx[0]%f \n",
                        sz,
                        sz->npt,
                        sz->tx[0]);

// the address is correct but
// here is the real problem: sz->npt = several billions
// sz->tx[0] = a stupid value
// the struct stab is not correctly passed in the function argument
// what can I do ??

...
}



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