我在Timer.h / .mm
中实现了这个定时器@implementation Timer
static multiset<Timer *> timers;
- (void) run
{
action();
if (!repeat)
{
timers.erase(timers.find(self));
}
}
+ (void) run: (Action) action after: (int) seconds repeat: (bool) rep
{
Timer * timer = [[Timer alloc] init];
timer->action = action;
timer->repeat = rep;
[NSTimer scheduledTimerWithTimeInterval:seconds
target:timer
selector:@selector(run)
userInfo:nil
repeats:rep];
// timers.insert(timer); // ANY version will fail
timers.insert([timer retain]);
}
@end
之后,我从我的UIViewController.mm中调用它:
[Timer run:^
{
// some code...
}
after:2];
但是当时间进入[定时器运行]时,它会随着EXC_BAD_ACCESS而下降!
#0 0x00000020 in ??
#1 0x000b87a5 in __NSFireTimer
#2 0x00dfafe3 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
我做错了什么?为什么叫cs:20h?我的程序中根本没有这样的价值(32)!
经过一些小改动后,计时器试图调用
#0 0x04ae6000 in ??
而不是
#0 0x00000020 in ??
当代码段位于0h(?)以外时〜15000H。