Fix a bug in Scheduler which may case Force Close

Fix a bug in Scheduler which may case Force Close
This commit is contained in:
waiter 2015-05-28 10:53:46 +08:00
parent 432ecbad41
commit 67a323e14a
1 changed files with 8 additions and 8 deletions

View File

@ -347,9 +347,9 @@ void Scheduler::unschedule(const std::string &key, void *target)
{ {
for (int i = 0; i < element->timers->num; ++i) for (int i = 0; i < element->timers->num; ++i)
{ {
TimerTargetCallback *timer = static_cast<TimerTargetCallback*>(element->timers->arr[i]); TimerTargetCallback *timer = dynamic_cast<TimerTargetCallback*>(element->timers->arr[i]);
if (key == timer->getKey()) if (timer && key == timer->getKey())
{ {
if (timer == element->currentTimer && (! element->currentTimerSalvaged)) if (timer == element->currentTimer && (! element->currentTimerSalvaged))
{ {
@ -528,9 +528,9 @@ bool Scheduler::isScheduled(const std::string& key, void *target)
{ {
for (int i = 0; i < element->timers->num; ++i) for (int i = 0; i < element->timers->num; ++i)
{ {
TimerTargetCallback *timer = static_cast<TimerTargetCallback*>(element->timers->arr[i]); TimerTargetCallback *timer = dynamic_cast<TimerTargetCallback*>(element->timers->arr[i]);
if (key == timer->getKey()) if (timer && key == timer->getKey())
{ {
return true; return true;
} }
@ -1056,9 +1056,9 @@ bool Scheduler::isScheduled(SEL_SCHEDULE selector, Ref *target)
{ {
for (int i = 0; i < element->timers->num; ++i) for (int i = 0; i < element->timers->num; ++i)
{ {
TimerTargetSelector *timer = static_cast<TimerTargetSelector*>(element->timers->arr[i]); TimerTargetSelector *timer = dynamic_cast<TimerTargetSelector*>(element->timers->arr[i]);
if (selector == timer->getSelector()) if (timer && selector == timer->getSelector())
{ {
return true; return true;
} }
@ -1088,9 +1088,9 @@ void Scheduler::unschedule(SEL_SCHEDULE selector, Ref *target)
{ {
for (int i = 0; i < element->timers->num; ++i) for (int i = 0; i < element->timers->num; ++i)
{ {
TimerTargetSelector *timer = static_cast<TimerTargetSelector*>(element->timers->arr[i]); TimerTargetSelector *timer = dynamic_cast<TimerTargetSelector*>(element->timers->arr[i]);
if (selector == timer->getSelector()) if (timer && selector == timer->getSelector())
{ {
if (timer == element->currentTimer && (! element->currentTimerSalvaged)) if (timer == element->currentTimer && (! element->currentTimerSalvaged))
{ {