cocos2d crash on callback

+1 vote
Build fingerprint: 'lge/b2lds_global_com/b2lds:4.4.2/KOT49I.A1420806068/1420806068:user/release-keys'
pid: 4817, tid: 4838, name: Thread-3095  >>> com.baiph.baiwordwars <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000
Stack frame #00  pc 00000000  <unknown>
Stack frame #01  pc 0028c6c5  /data/app-lib/com.baiph.baiwordwars-1/libcocos2dcpp.so (MainMenu::energy_update()+108): Routine MainMenu::energy_update() at /home/soysoy/baiph/3.3final/WordWars/proj.android/jni/../../Classes/MainMenu.cpp:1116
 
line MainMenu.cpp:1116 is:
 
void MainMenu::energy_update() // update on UI
{
 
float finalscale;
if(energy_num>ENERGY_MAX)
finalscale = (bar_max/ENERGY_MAX)*ENERGY_MAX;
else
finalscale = (bar_max/ENERGY_MAX)*energy_num;
energy_bar->setScale(finalscale,GETSCALEY*1.24);
energy_bar->setPosition(energy_base->getPositionX()*0.46+energy_bar->getBoundingBox().size.width/2,
energy_base->getPositionY()*1.005);
std::string energy_str = std::to_string(energy_num);
energy_str.append("/");
energy_str.append(std::to_string(ENERGY_MAX));
energy->setString(energy_str);
energy->setPosition(energy_base->getPositionX()*1.1,energy_bar->getPositionY()*0.97);
 
if(isFirstLaunch)
{
isFirstLaunch = !isFirstLaunch;
def->setBoolForKey("isFirstLaunch",isFirstLaunch);
def->flush();
}
 
rewardDone=true;
if(!connected)
{
hide_layer(network_layer, true, 0);
hide_layer(HUD_main, false, 255);
hide_layer(main_menu, false, 255);
}
main_menu->setEnabled(true);
requests_menu->setEnabled(true);
challenge_menu->setEnabled(true);
 
connected = true;
}

the function energy_update is called by

void MainMenu::onTimerServiceRequestCompleted( void *response, std::string action)
{
log("//*************************************************//");
log("\nonTimerServiceRequestCompleted... action %s", action.c_str());
App42TimerResponse *app42TimerResponse = (App42TimerResponse*)response;
if(app42TimerResponse->isSuccess)
{
log("\nResponse Body=%s",app42TimerResponse->getBody().c_str());
if(action=="CREATE")
{
timeLeft = TIME_PER_ENERGY_S;
timerService->CreateOrUpdateTimer(timerName.c_str(),timeLeft,app42callback(MainMenu::onTimerServiceRequestCompleted, this, "START"));
}
else if(action=="START")
{
timerService->StartTimer(timerName.c_str(),userName.c_str(),app42callback(MainMenu::onTimerServiceRequestCompleted, this, "STARTED"));
}
else if(action=="STARTED")
{
 
auto scheduler = Director::getInstance()->getScheduler();
scheduler->performFunctionInCocosThread(CC_CALLBACK_0(MainMenu::time_diff, this,app42TimerResponse->app42Timer.endTime, app42TimerResponse->app42Timer.startTime));
scheduler->performFunctionInCocosThread(CC_CALLBACK_0(MainMenu::energy_update, this));
isCounting = true;
}
else if(action=="CURRENTTIME")
{
if(energy_num<ENERGY_MAX)
{
server_time = app42TimerResponse->app42Timer.currentTime; //CURRENT TIME
time_diff(server_end, server_time);
auto scheduler = Director::getInstance()->getScheduler();
scheduler->performFunctionInCocosThread(CC_CALLBACK_0(MainMenu::energy_update, this));
isCounting = true;
}
}
else if(action=="CHECK")//UPDATES
{
if(app42TimerResponse->app42Timer.isTimerActive)
{
server_end = app42TimerResponse->app42Timer.endTime;
server_start = app42TimerResponse->app42Timer.startTime;
timerService->GetCurrentTime(app42callback(MainMenu::onTimerServiceRequestCompleted, this,"CURRENTTIME"));
}
else if(energy_num<ENERGY_MAX)
{
//double energy_max = 3;
double energy_lost = ENERGY_MAX-energy_num;
 
auto scheduler = Director::getInstance()->getScheduler();
 
scheduler->performFunctionInCocosThread(CC_CALLBACK_0(MainMenu::add_energy, this,true,energy_lost,"TIMER_CREATE"));
}
}
else if(action=="ADD_ON_RUNTIME")
{
auto scheduler = Director::getInstance()->getScheduler();
 
scheduler->performFunctionInCocosThread(CC_CALLBACK_0(MainMenu::add_energy, this,true,1,"UPDATE_UI"));
if(app42TimerResponse->app42Timer.isTimerActive)
{
 
server_end = app42TimerResponse->app42Timer.endTime;
timerService->GetCurrentTime(app42callback(MainMenu::onTimerServiceRequestCompleted, this,"CURRENTTIME"));
}
}
}
else
{
log("\nerrordetails:%s",app42TimerResponse->errorDetails.c_str());
log("\nerrorMessage:%s",app42TimerResponse->errorMessage.c_str());
log("\nappErrorCode:%d",app42TimerResponse->appErrorCode);
log("\nhttpErrorCode:%d",app42TimerResponse->httpErrorCode);
 
if((action=="CREATE") || (action=="START") ||(action=="STARTED"))
{
auto scheduler = Director::getInstance()->getScheduler();
 
scheduler->performFunctionInCocosThread(CC_CALLBACK_0(MainMenu::energy_update, this));
}
 
}
log("//*************************************************//");
}
 
Problem is, If there is an on going requests and then I switch scene the callback is still fired. Is there a way to stop the callback?
asked Apr 18, 2015 in App42PaaS & BPaaS by jvfiel (35 points)

1 Answer

0 votes
Hi,

You can not cancel an on-going request. But you can avoid this situation by creating a helper class(A singleton class) for handling App42 SDK requests. Every requests will originate from this class and response will be delivered to this class. When response comes to the helper class it can check for the scene existence and if scene exists then only pass the response to the scene.

Let us know if it helps.

Thanks.
answered Apr 18, 2015 by rajeev.etc (1,660 points)
do you have some samples? As of now I use this Director::getInstance()->pushScene(Highscores::scene()); instead of replaceScene(). It somehow solved the crash
Yes, pushScene will also work because instead of removing the previous scene it stores it in the stack.
For now, we do not have ready made sample that handles this particular case, but if you need it from our side we can create one and it will take some time(approx. 2-3 days) as we have other scheduled tasks.
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...