diff --git a/src/main_loop.cpp b/src/main_loop.cpp index 53d781108..d91981b94 100644 --- a/src/main_loop.cpp +++ b/src/main_loop.cpp @@ -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); } } } diff --git a/src/online/http_request.cpp b/src/online/http_request.cpp index 42becf2cc..302e3ab06 100644 --- a/src/online/http_request.cpp +++ b/src/online/http_request.cpp @@ -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 diff --git a/src/online/request_manager.cpp b/src/online/request_manager.cpp index dd594366c..63bdb1097 100644 --- a/src/online/request_manager.cpp +++ b/src/online/request_manager.cpp @@ -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(); diff --git a/src/online/request_manager.hpp b/src/online/request_manager.hpp index 2e993d99d..1774020fa 100644 --- a/src/online/request_manager.hpp +++ b/src/online/request_manager.hpp @@ -33,6 +33,7 @@ # include #endif +#include #include #include #include @@ -103,6 +104,9 @@ namespace Online /** Signal an abort in case that a download is still happening. */ Synchronised 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); // ----------------------------------------------------------------