Gotcha: Segmentation Fault in Trigger callback

KildClient forum.
Post Reply
rumex
Posts: 7
Joined: Mon Feb 06, 2012 10:20 pm

Gotcha: Segmentation Fault in Trigger callback

Post by rumex »

FYI: I spent a frustrating while realising that deleting a timer from within code called by that timer triggering was a bad idea.
The solution was to use distimer instead.

[this is a summary of a thread on the old nabble forum]
jmud
Posts: 19
Joined: Mon Jun 04, 2012 4:59 am

Re: Gotcha: Segmentation Fault in Trigger callback

Post by jmud »

If you really want to delete the timer, you could add it to a global list:

Code: Select all

# Create a global variable
our @DeleteTimerList;

# Create a KildClient timer
$::world->timer(
            {
                name => $timerName,
                interval => $timerInterval,
                action => $timerAction,
            }
);

# When you want to delete the timer, add it to death row
push (@DeleteTimerList, $timerName);
Also, you can create a second timer that calls a function in your plugin, that empties @DeleteTimerList periodically.

Code: Select all

$::world->timer(
            {
                name => 'Grim_reaper',
                interval => 1,
                action => '/myplugin->deleteMyTimers(),
            }
);

...

sub deleteMyTimer {

	foreach my $timerName (@DeleteTimerList) {
		
		$result = $::world->deltimer($timerName);
	}
}
This should guarantee that you never delete the timer, from within the Perl code it calls. (It's probably simpler to use distimer, as you say.)
Post Reply