Hi,
While developing a game for iOS and Android, I ran into an issue:
I want to use c++ std::thread to write some data to UserDefault. The problem is, the app crashes with the following error:
D/dalvikvm(13181): threadid=13: thread exiting, not yet detached (count=0)
D/dalvikvm(13181): threadid=13: thread exiting, not yet detached (count=1)
E/dalvikvm(13181): threadid=13: native thread exited without detaching
To start the thread, I use the following code (which works perfectly on windows and iOS):
std::thread backgroundThread(&Example::clearAllLevelProgressInBackground, this);
backgroundThread.detach();
The clearAllLevelProgressInBackground is just something like the following code:
auto userDefault = UserDefault::getInstance();
//a lot of:
userDefault->setIntegerFor.....
//etc.
userDefault->flush();
getScheduler()->schedule(schedule_selector(Example::afterLevelsCleared), this, 0, 0, 0, false);
I don’t know what the issue is, as I do not retain or release anything (the manual warned about this). Without the thread the code works fine, but the UI freezes for a while, which is why I used a thread. Does anybody know what this is?