diff --git a/src/guiengine/event_handler.cpp b/src/guiengine/event_handler.cpp index cc3543aee..1aadc8cb5 100644 --- a/src/guiengine/event_handler.cpp +++ b/src/guiengine/event_handler.cpp @@ -19,6 +19,7 @@ #ifdef ANDROID #include "addons/addons_manager.hpp" +#include "io/file_manager.hpp" #endif #include "audio/music_manager.hpp" #include "audio/sfx_manager.hpp" @@ -181,21 +182,29 @@ bool EventHandler::OnEvent (const SEvent &event) if (cmd == APP_CMD_PAUSE || cmd == APP_CMD_LOST_FOCUS) { // Make sure that pause/unpause is executed only once - if (music_manager && device->isWindowMinimized() == device->isWindowFocused()) + if (device->isWindowMinimized() == device->isWindowFocused()) { - music_manager->pauseMusic(); - SFXManager::get()->pauseAll(); + if (music_manager) + music_manager->pauseMusic(); + if (SFXManager::get()) + SFXManager::get()->pauseAll(); + PlayerManager::get()->save(); + if (addons_manager->hasDownloadedIcons()) + addons_manager->saveInstalled(); + // Clean temp files manually as destructor of file manager + // won't be called at all in mobile if user just press home + // button + file_manager->cleanTempFiles(); } - PlayerManager::get()->save(); - if (addons_manager->hasDownloadedIcons()) - addons_manager->saveInstalled(); } else if (cmd == APP_CMD_RESUME || cmd == APP_CMD_GAINED_FOCUS) { - if (music_manager && device->isWindowActive()) + if (device->isWindowActive()) { - music_manager->resumeMusic(); - SFXManager::get()->resumeAll(); + if (music_manager) + music_manager->resumeMusic(); + if (SFXManager::get()) + SFXManager::get()->resumeAll(); // Improve rubber banding effects of rewinders when going // back to phone, because the smooth timer is paused if (World::getWorld() && RewindManager::isEnabled()) diff --git a/src/io/file_manager.cpp b/src/io/file_manager.cpp index 2d2927cbd..a1623ae5a 100644 --- a/src/io/file_manager.cpp +++ b/src/io/file_manager.cpp @@ -453,6 +453,20 @@ void FileManager::reinitAfterDownloadAssets() //----------------------------------------------------------------------------- FileManager::~FileManager() +{ + cleanTempFiles(); + // Clean up rest of file manager + // ============================= + popMusicSearchPath(); + popModelSearchPath(); + popTextureSearchPath(); + popTextureSearchPath(); + m_file_system->drop(); + m_file_system = NULL; +} // ~FileManager + +// ---------------------------------------------------------------------------- +void FileManager::cleanTempFiles() { // Clean up left-over files in addons/tmp that are older than 24h // ============================================================== @@ -498,16 +512,7 @@ FileManager::~FileManager() removeFile(full_path); } // for i in all files in tmp - - // Clean up rest of file manager - // ============================= - popMusicSearchPath(); - popModelSearchPath(); - popTextureSearchPath(); - popTextureSearchPath(); - m_file_system->drop(); - m_file_system = NULL; -} // ~FileManager +} // cleanTempFiles // ---------------------------------------------------------------------------- /** Returns true if the specified file exists. diff --git a/src/io/file_manager.hpp b/src/io/file_manager.hpp index 5226f357c..a3f9d8dd6 100644 --- a/src/io/file_manager.hpp +++ b/src/io/file_manager.hpp @@ -245,7 +245,8 @@ public: // ------------------------------------------------------------------------ const std::string& getCertBundleLocation() const { return m_cert_bundle_location; } - + // ------------------------------------------------------------------------ + void cleanTempFiles(); }; // FileManager extern FileManager* file_manager; diff --git a/src/main_loop.cpp b/src/main_loop.cpp index e35121af8..faf49cd23 100644 --- a/src/main_loop.cpp +++ b/src/main_loop.cpp @@ -130,19 +130,27 @@ float MainLoop::getLimitedDt() if (first_out_focus) { first_out_focus = false; - music_manager->pauseMusic(); - SFXManager::get()->pauseAll(); + if (music_manager) + music_manager->pauseMusic(); + if (SFXManager::get()) + SFXManager::get()->pauseAll(); PlayerManager::get()->save(); if (addons_manager->hasDownloadedIcons()) addons_manager->saveInstalled(); + // Clean temp files manually as destructor of file manager + // won't be called at all in mobile if user just press home + // button + file_manager->cleanTempFiles(); } dev->run(); win_active = dev->isWindowActive(); has_focus = dev->isWindowFocused(); if (has_focus && win_active) { - music_manager->resumeMusic(); - SFXManager::get()->resumeAll(); + if (music_manager) + music_manager->resumeMusic(); + if (SFXManager::get()) + SFXManager::get()->resumeAll(); // Improve rubber banding effects of rewinders when going // back to phone, because the smooth timer is paused if (World::getWorld() && RewindManager::isEnabled())