Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2001:
[Freeciv-Dev] Re: possible segfault and help!

[Freeciv-Dev] Re: possible segfault and help!

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: possible segfault and help!
From: Kero van Gelder <kero@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 14 Mar 2001 00:20:12 +0100
Reply-to: kero@xxxxxx

> I'm wondering if my example discounts at least part of that. If, for
> example, the callback didn't run until after the calling function had
> completed, then my program would segfault no matter which toggle button
> wasactivated.

Guess you're right; I should pay more attention.

> > As I just learned from David, gtk uses an event-loop, so the callback
> > triggered by setting the radio-button to zero, will be executed
> > _after_ the current function is completely finished and control is
> > passed back to gtk.
> If that were true, then in the example program below, the printf would
> never print 1, it would always print 0. 

Prints 1 for me.

> What I found out (after posting, of course) was that if I set a toggle
> active before registering the callback and then set it true again, it
> won't trigger the callback (not even to unset and then set it
> again). Also, if I set all the toggles false before registering the
> callback, gtk will automatically set the 0th button true. (which is also
> why my 'patch' to dialogs.c is bogus)
> Solution: block the signal and place the relevant code in the calling
> function.

Sounds OK to me.

> > 'coz if an event would trigger a new function _before_ finishing its
> > current function, you would immediately have multiple threads when the
> > _user_ creates a new event.
> now maybe my example is tangential since my code generates the event
> rather than a user clicking a button...

Perhaps. I tried a bit of hacking.

I changed your callback a bit:

static void races_toggles_callback( GtkWidget *w, struct dlg *en)
  int i;
  for (i=0; i<en->i; i++) printf("  ");
  printf("--> %d\n", en->i);fflush(stdout);/* DEBUG */
  if (en->i < LIMIT) 
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(en->races_toggles[en->i]), TRUE );
  for (i=0; i<en->i; i++) printf("  ");
  printf("<-- %d\n", en->i);fflush(stdout);/* DEBUG */

and pressed a few buttons (LIMIT is 5, or 4 to prevent too long lists).
I must admit I have no clue why things happen as they happen here :-(
e.g. I get long lists for buttons 0 and 3 (LIMIT 4), but a very short
list when I press 1. YMMV, what do you get?

gtk is nice, but I'll have to use it before I'm an expert in its

And yes, we're moving off-topic here, may be we should move off the


+--- Kero --------------------------------- kero@xxxxxx ---+
|  Don't split your mentality without thinking twice       |
|                          Proud like a God -- Guano Apes  |
+--- M38c ------------------ ---+

[Prev in Thread] Current Thread [Next in Thread]