the mysterious pointer error



I've rewritten my code 3 times, but I can't find the source of my
trouble...
I got a piece of code here, part of a game written in C and GTK,
and there's something wrong with a value that I try to change in a
structure I made
that doesn't get changed... because I can't pass my pointer to the
structure properly.
might just be me, but if someone else with a little more GTK knowledge
would like to check it
out I'd be very grateful.
I think it's got something to do with the gtk_signal_connect() function
and the g_timeout_add() function
and how they work...

here's the tarball with the source: (I thought attaching would be rude
hehe)

http://gene.wins.uva.nl/~wrvhage/download/gquest-0.0.18-2.tar.gz

the problem's somewhere in xfuncs.c and gamec.c,
in xfuncs.c there's the function "void init_widgets(GameControl**
gamec);", and in that function
"gtk_signal_connect(GTK_OBJECT(MAP_WINDOW),"key_press_event",GTK_SIGNAL_FUNC(key_interface),gamec);"
that means gamec is a GameControl**... in gamec.c the function "void
key_interface(GameControl** gamec,GdkEventKey* event);"
uses "gamec" again and changes the value of "(*gamec)->game_state...
with some mask macros... the problem is not the
macro's as you can see by the print statements that show that the mask
has been changed every time
you press the key "p"... but when I refer to (*gamec)->game_state in the
function "void void do_cycle(GameControl** gamec);"
after "(*gamec)->game_state" has been changed nothing seems to have
happened...
that's because the gamec I have in do_cycle() points to a different
address than the one in key_interface()...
even though I both get them through init_widgets() where they still
point to the same address.
It's weird.
I tried making simple C without GTK models for the problem, but they
don't have the error,
I think it's something with the g_timeout_add() and the
gtk_signal_connect() that does something with the pointer...
make a copy of it or something...
thanks in advance for looking at it,

Willem van Hage

-- 
wrvh@xs4all.nl      | http://www.xs4all.nl/~wrvh
wrvhage@wins.uva.nl | http://gene.wins.uva.nl/~wrvhage



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