mirror of https://github.com/axmolengine/axmol.git
Merge pull request #10241 from Dhilan007/v3-scheduled-fix
Fixed may access wrong memory address in Scheduler::schedule
This commit is contained in:
commit
80cf4439f2
|
@ -311,9 +311,9 @@ void Scheduler::schedule(const ccSchedulerFunc& callback, void *target, float in
|
|||
{
|
||||
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())
|
||||
{
|
||||
CCLOG("CCScheduler#scheduleSelector. Selector already scheduled. Updating interval from: %.4f to %.4f", timer->getInterval(), interval);
|
||||
timer->setInterval(interval);
|
||||
|
@ -1012,9 +1012,9 @@ void Scheduler::schedule(SEL_SCHEDULE selector, Ref *target, float interval, uns
|
|||
{
|
||||
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())
|
||||
{
|
||||
CCLOG("CCScheduler#scheduleSelector. Selector already scheduled. Updating interval from: %.4f to %.4f", timer->getInterval(), interval);
|
||||
timer->setInterval(interval);
|
||||
|
|
|
@ -29,7 +29,8 @@ static std::function<Layer*()> createFunctions[] = {
|
|||
CL(SchedulerDelayAndRepeat),
|
||||
CL(SchedulerIssue2268),
|
||||
CL(ScheduleCallbackTest),
|
||||
CL(ScheduleUpdatePriority)
|
||||
CL(ScheduleUpdatePriority),
|
||||
CL(SchedulerIssue10232)
|
||||
};
|
||||
|
||||
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
|
||||
|
@ -1212,3 +1213,29 @@ void SchedulerTestScene::runThisTest()
|
|||
|
||||
Director::getInstance()->replaceScene(this);
|
||||
}
|
||||
|
||||
void SchedulerIssue10232::onEnter()
|
||||
{
|
||||
SchedulerTestLayer::onEnter();
|
||||
|
||||
this->scheduleOnce(SEL_SCHEDULE(&SchedulerIssue2268::update), 0.25f);
|
||||
|
||||
this->scheduleOnce([](float dt){
|
||||
log("SchedulerIssue10232:Schedules a lambda function");
|
||||
}, 0.25f,"SchedulerIssue10232");
|
||||
}
|
||||
|
||||
void SchedulerIssue10232::update(float dt)
|
||||
{
|
||||
log("SchedulerIssue10232:Schedules a selector");
|
||||
}
|
||||
|
||||
std::string SchedulerIssue10232::title() const
|
||||
{
|
||||
return "Issue #10232";
|
||||
}
|
||||
|
||||
std::string SchedulerIssue10232::subtitle() const
|
||||
{
|
||||
return "Should not crash";
|
||||
}
|
||||
|
|
|
@ -330,4 +330,16 @@ public:
|
|||
virtual void runThisTest();
|
||||
};
|
||||
|
||||
class SchedulerIssue10232 : public SchedulerTestLayer
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(SchedulerIssue10232);
|
||||
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
void onEnter();
|
||||
void update(float dt);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue