Re: [PHP-GTK] Segfault on toggle callback with GtkCheckButton
[email protected] (Jake Cobb)
| Newsgroups | php.gtk.general |
|---|---|
| Message-ID | <[email protected]> |
Hello,
You are creating an infinite loop that is causing the seg fault. The
set_active() call in your class triggers the 'toggled' signal which it
is a handler for. There is a built-in handler changing the active state
in response to user clicks already that causes the original 'toggled'
signal to be emitted. If you store your handler's handle, you can block
and unblock it around the set_active() calls to prevent the crash.
However, since you are reacting to a 'toggled' event by toggling, this
has the effect of making the user unable to toggle the box; your handler
would react and revert its state. Try this modified version:
class testClass
{
private $gtkButton;
private $toggleSignal;
public function createButton()
{
$this->gtkButton = new GtkCheckButton("My Label");
$this->toggleSignal = $this->gtkButton->connect_simple('toggled', array($this, 'selectedEvent'));
}
public function getButton() { return $this->gtkButton; }
public function selectedEvent()
{
$this->gtkButton->block($this->toggleSignal);
if($this->gtkButton->get_active())
$this->gtkButton->set_active(false);
else
$this->gtkButton->set_active(true);
$this->gtkButton->unblock($this->toggleSignal);
}
}
-Jake Cobb
[email protected] wrote:
> Hi All,
>
> I'm new to PHP-GTK, but I've got a fairly strong background using gtk and C. I've been attempting to set up a callback function that is called whenever a GtkCheckButton is toggled, but I'm getting a segfault every time. I've reproduced the crash in the below code.
>
> This is running on Ubuntu 7.10/Gutsy using the Ubuntu 5.2.3 php5-cli executable.
>
> Any ideas? xdebug isn't giving me any stacktrace on the segfault, so I assume that means the php executable itself is crashing.
>
> Thanks,
>
> -- Alex Augot
>
> ///////////////////////////
> Code
> ///////////////////////////
> <?php
> // Toggle Button Crash Test
>
> class testClass
> {
> private $gtkButton;
>
> public function createButton()
> {
> $this->gtkButton = new GtkCheckButton("My Label");
> $this->gtkButton->connect_simple('toggled', array($this, 'selectedEvent'));
> }
>
> public function getButton() { return $this->gtkButton; }
>
> public function selectedEvent()
> {
> if($this->gtkButton->get_active())
> $this->gtkButton->set_active(false);
> else
> $this->gtkButton->set_active(true);
> }
> }
>
> // Create the test button
> $testButton = new testClass();
> $testButton->createButton();
>
> // Create a test window, hbox, and add
> // the button to it. When button is toggled, it segfaults
> $gtkWindow = new GtkWindow();
> $gtkBox = new GtkHBox();
>
> $gtkWindow->add($gtkBox);
> $gtkBox->add($testButton->getButton());
>
> $gtkWindow->set_visible(true);
>
> Gtk::main();
> ?>
>
>