开发者

[C]Dynamic allocation memory of structure, related to GTK

I have following structure:

    typedef struct
{
 GtkWidget* PoziomaLinijka;
 GtkWidget* PionowaLinijka;
 GtkWi开发者_如何学Pythondget* Label1;
 GtkWidget* Label2;
 gint x,y;
} StrukturaDrawing;

And i need to allocate it on the heap because later I have functions which uses that structure and I don't want to use global variables. So I allocate it like this:

    StrukturaDrawing* Wsk;
  Wsk = (StrukturaDrawing*)malloc(sizeof(StrukturaDrawing));
  if (!Wsk)
  {
 printf("Error\n");
  }

And it doesn't returning error and also works great with other functions, it works the way I wanted it to work so finally i wanted to free that memory and here is problem because in Debug Mode compilator bitches:

First-chance exception at 0x102d12b4 in GTK.exe: 0xC0000005: Access violation reading location 0xfffffffc. Unhandled exception at 0x102d12b4 in GTK.exe: 0xC0000005: Access violation reading location 0xfffffffc.

I connect callback to my function, like that:

g_signal_connect(G_OBJECT(Okno), "destroy", G_CALLBACK(Wyjscie), Wsk);

Function which is suppose to free memory and close program:

void Wyjscie(GtkWindow* window, GdkEvent* event, StrukturaDrawing* data)
{
 gtk_main_quit();
 free(data);
 data = NULL;
}

Any help really appreciated.


Well durning debugging data structure have following values: The first one has: PoziomaLinijka CXX0017: Error: symbol "" not found And later the whole rest have: PionowaLinijka CXX0030: Error: expression cannot be evaluated

Oh: I am the oen who started question, sorry about confusing with nicknames.


The "destroy" signal has a different signature for its callback than your Wyjscie function. Maybe you rather want the "destroy-event" of GtkWidget, see docshere

If you want the "destroy" event of GtkObject, see here, you have to change your callback to

void Wyjscie(GtkObject* window,StrukturaDrawing* data)
{
 gtk_main_quit();
 free(data);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜