From e0f1f3b4d1860143070d15501e19546680ed664a Mon Sep 17 00:00:00 2001 From: Ethan Yonker Date: Tue, 27 Oct 2015 09:49:01 -0500 Subject: Move reloading of theme outside of the action thread Reloading the GUI while the GUI is running and rendering is very dangerous as we may be deleting GUI resources before or while we are trying to render those same items. This change will allow us to safely load new resources and delete the old ones. Fixed a double free situation that was causing a crash on every other theme reload. Clear parsed xml documents when we are done loading the theme instead of keeping them in memory for the life of the theme to help save a little memory. Store starting page so that if we request a reload, we can enter the theme at the same starting point, which may come in handy if we allow for language selection on alternate starting pages such as the decrypt prompt or the system read only prompt. Change-Id: I45a7e3fb3daeefac56d70f8d4936938eb1244b99 --- gui/action.cpp | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'gui/action.cpp') diff --git a/gui/action.cpp b/gui/action.cpp index 86907a54f..c48c390f9 100644 --- a/gui/action.cpp +++ b/gui/action.cpp @@ -541,26 +541,13 @@ int GUIAction::page(std::string arg) int GUIAction::reload(std::string arg __unused) { - int check = 0, ret_val = 0; - std::string theme_path; - - theme_path = DataManager::GetSettingsStoragePath(); - if (PartitionManager.Mount_By_Path(theme_path.c_str(), 1) < 0) { - LOGERR("Unable to mount %s during reload function startup.\n", theme_path.c_str()); - check = 1; - } - - theme_path += "/TWRP/theme/ui.zip"; - if (check != 0 || PageManager::ReloadPackage("TWRP", theme_path) != 0) - { - // Loading the custom theme failed - try loading the stock theme - LOGINFO("Attempting to reload stock theme...\n"); - if (PageManager::ReloadPackage("TWRP", TWRES "ui.xml")) - { - LOGERR("Failed to load base packages.\n"); - ret_val = 1; - } - } + PageManager::RequestReload(); + // The actual reload is handled in pages.cpp in PageManager::RunReload() + // The reload will occur on the next Update or Render call and will + // be performed in the rendoer thread instead of the action thread + // to prevent crashing which could occur when we start deleting + // GUI resources in the action thread while we attempt to render + // with those same resources in another thread. return 0; } -- cgit v1.2.3