Adjust code execute order, used a simple and safe way to avoid access fail bug.

This commit is contained in:
XiaoFeng 2015-10-22 14:36:26 +08:00
parent 3d626940af
commit 6beb982665
2 changed files with 6 additions and 8 deletions

View File

@ -698,7 +698,6 @@ namespace cocos2d { namespace network {
DownloaderCURL::DownloaderCURL(const DownloaderHints& hints)
: _impl(std::make_shared<Impl>())
, _currTask(nullptr)
, _breakScheduleFunc(false)
{
DLLOG("Construct DownloaderCURL %p", this);
_impl->hints = hints;
@ -732,7 +731,6 @@ namespace cocos2d { namespace network {
DownloaderCURL::~DownloaderCURL()
{
_breakScheduleFunc = true;
_scheduler->unschedule(_schedulerKey, this);
_scheduler->release();
@ -781,6 +779,12 @@ namespace cocos2d { namespace network {
// update finished tasks
_impl->getFinishedTasks(tasks);
if (_impl->stoped())
{
_scheduler->pauseTarget(this);
}
for (auto& wrapper : tasks)
{
const DownloadTask& task = *wrapper.first;
@ -846,11 +850,6 @@ namespace cocos2d { namespace network {
onTaskFinish(task, coTask._errCode, coTask._errCodeInternal, coTask._errDescription, coTask._buf);
DLLOG(" DownloaderCURL: finish Task: Id(%d)", coTask.serialId);
}
if (!_breakScheduleFunc && _impl->stoped())
{
_scheduler->pauseTarget(this);
}
}
}} // namespace cocos2d::network

View File

@ -55,7 +55,6 @@ namespace cocos2d { namespace network
void _onSchedule(float);
std::string _schedulerKey;
Scheduler* _scheduler;
bool _breakScheduleFunc;
};
}} // namespace cocos2d::network