[SOLVED] App freezing after updating TTF Labels for about 7s (on emulator)

The following is all I call in update

void MyScene::updateClock() {
        static int lastMinute = 0;
        char str[10] = {0};
        time_t rawtime;
        struct tm * timeinfo;
        time(&rawtime);
        timeinfo = localtime (&rawtime);
        if (forceClockUpdate || lastMinute != timeinfo->tm_min) {
            lastMinute = timeinfo->tm_min;
            forceClockUpdate = false;
            strftime (str, 9,"%R",timeinfo);
            pTimeLabel->setString(str);
        }
}

I was updating another timer in there but the app would crash, on the emulator (only), after about 7 seconds. I removed that update and I had at least 20 seconds to play, inspect the log etc but upon returning to it I found that it had frozen again. Even the cocos2d-x stuff like framerate in the bottom left had stopped. I’m using TTF for my label, could it be that running too slow? I doubt it because whatever refresh I stipulate

schedule(schedule_selector(MyScene::update), 1.2f); //or
    scheduleUpdate();

It still tends to lock up. Before I changed the data structure it was alright, but the old data structure was so unwieldly that the whole app was being debugged on my phone only.

Thanks.

UPDATE
This one isn’t working on my phone at all, as it attempts to load I get a brief message about waiting for debugger and, ohhh, there it goes logcat is scrolling but the screen refuses to turn back on :smile:
Fixed that but not risking my phone again. After removing updating the TTFLabel it seemed okay. Had some errors returned when I attempted to close it, about heap allocations, tried fixing them and now it just refuses to build citing errors with four of my “.o” files.

Development with Visual Studio was childs play compared to this.

UPDATE2
I had some joy on the emulator, only after restarting eclipse and the emulator. The joy ended as soon as I reinstated the second part of the update routine described, but not shown above:

if (hasTime) {
        sprintf(str, “%d:%2d”, int(timeRemaining) / 60, int(timeRemaining) % 60);
        pTimerLabel->setString(str);
    }

This would update 50x/second so could understandably cause a hang. Or worse. So restarted my emulator and made a static local to detect when the second had changed. It was still failing after 7s despite having only introduced “nominal” overhead. I removed it altogether and it last at least 20s.

On start up I am getting the following message:

Which I’ve only had since I introduced a new quarter second (on emulator) task to occur before the first screen.

If I understand correctly, the screen freeze due to the code you post.

When the screen freeze, it doesn’t mean your method is slow. It means your method is blocking. If your method is merely slow, your framerate will drop, but won’t stop (unless it was changed in V3, but I doubt that).

The most fishy thing going on for me is in your second snippet (in update 2): is “str” the same 10 characters variable? If so, there is a risk of buffer overflow depending on timeRemaining size. You may want to use snprintf to limit the size, or manually check the size of timeRemaining.

If it isn’t that, try to remove line by line until it doesn’t freeze, and tell us what exact line is causing the problem.

There is also a chance the problem comes from an entire other part of your code that only arise in certain circustances and that part actually make the bug happen.

Thank you for your reply @Fradow

Yes that exact pair of lines is repsonsible for the hanging. As I am well aware of the hazzards of multithreading and early optimization I delegated that out to my Visual Studio and have tried to only import known good code to my cocos2d-x Android project. Let me reiterate, and recheck… I have no other threads.

sprintf(str, “%d:%2d”, int(timeRemaining) / 60, int(timeRemaining) % 60);
        pTimerLabel->setString(str);

I was concerned about the string overflow but that is 10 chars and impossible for an HH:MM time to overflow it.

Freezing is only one of my problems, the warning on boot up is worrying and I’d like to batch the loading of my data to a thread, later. Most important to me at the moment, and gives me something other than the freezing to work on, (hey, anybody know any more about the freezing?) is integrating my new algo’s fresh out of Visual Studio. I’m getting memory management issues as I transition scenes, something I couldn’t do with VS.

I think I spotted disgusting memory leak in one of my good old non-managed array members, that’d cause a lot of strangeness.

EDIT Yup that’s the error right enough, thank you for your direction.