Pause request in iOS STK to avoid crash when pressing home button
This commit is contained in:
@@ -137,6 +137,7 @@ float MainLoop::getLimitedDt()
|
||||
PlayerManager::get()->save();
|
||||
if (addons_manager->hasDownloadedIcons())
|
||||
addons_manager->saveInstalled();
|
||||
Online::RequestManager::get()->setPaused(true);
|
||||
}
|
||||
dev->run();
|
||||
win_active = dev->isWindowActive();
|
||||
@@ -151,6 +152,7 @@ float MainLoop::getLimitedDt()
|
||||
// back to phone, because the smooth timer is paused
|
||||
if (World::getWorld() && RewindManager::isEnabled())
|
||||
RewindManager::get()->resetSmoothNetworkBody();
|
||||
Online::RequestManager::get()->setPaused(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,7 +360,8 @@ namespace Online
|
||||
// Check if we are asked to abort the download. If so, signal this
|
||||
// back to libcurl by returning a non-zero status.
|
||||
if (RequestManager::isRunning() &&
|
||||
(RequestManager::get()->getAbort() || request->isCancelled()) &&
|
||||
(RequestManager::get()->getAbort() || RequestManager::get()->getPaused() ||
|
||||
request->isCancelled()) &&
|
||||
request->isAbortable() )
|
||||
{
|
||||
// Indicates to abort the current download, which means that this
|
||||
|
||||
@@ -69,6 +69,7 @@ namespace Online
|
||||
*/
|
||||
RequestManager::RequestManager()
|
||||
{
|
||||
m_paused.store(false);
|
||||
m_menu_polling_interval = 60; // Default polling: every 60 seconds.
|
||||
m_game_polling_interval = 60; // same for game polling
|
||||
m_time_since_poll = m_menu_polling_interval;
|
||||
@@ -210,6 +211,10 @@ namespace Online
|
||||
pthread_cond_wait(&me->m_cond_request, me->m_request_queue.getMutex());
|
||||
empty = me->m_request_queue.getData().empty();
|
||||
}
|
||||
// We pause the request manager thread when going into background in iOS
|
||||
// So this will only be evaluated a while
|
||||
if (me->m_paused.load())
|
||||
StkTime::sleep(1);
|
||||
me->m_current_request = me->m_request_queue.getData().top();
|
||||
me->m_request_queue.getData().pop();
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
# include <winsock2.h>
|
||||
#endif
|
||||
|
||||
#include <atomic>
|
||||
#include <curl/curl.h>
|
||||
#include <memory>
|
||||
#include <queue>
|
||||
@@ -103,6 +104,9 @@ namespace Online
|
||||
/** Signal an abort in case that a download is still happening. */
|
||||
Synchronised<bool> m_abort;
|
||||
|
||||
/** Signal an pause before STK goes into background in iOS. */
|
||||
std::atomic_bool m_paused;
|
||||
|
||||
/** The polling interval while a game is running. */
|
||||
float m_game_polling_interval;
|
||||
|
||||
@@ -160,6 +164,8 @@ namespace Online
|
||||
void stopNetworkThread();
|
||||
|
||||
bool getAbort() { return m_abort.getAtomic(); }
|
||||
bool getPaused() { return m_paused.load(); }
|
||||
void setPaused(bool val) { m_paused.store(val); }
|
||||
void update(float dt);
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user