Skip to content

Commit

Permalink
Tuning: Fixed crash during manual cache regen.
Browse files Browse the repository at this point in the history
Reported by CuriousMike: "load map, spawn any vehicle, go back to main menu, click settings -> general -> update cache".

Fixed by introducing a rule "we just always load subdirs as 'writable', even during modcache update."
  • Loading branch information
ohlidalp committed Dec 31, 2023
1 parent 56927a5 commit 5870b93
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions source/main/resources/ContentManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ void ContentManager::InitContentManager()
void ContentManager::InitModCache(CacheValidity validity)
{
// Sets up RGN_CONTENT which encompasses all mods, scans it for changes and deletes it again.
// IMPORTANT NOTE ON 'readOnly' FLAG:
// We need mods in subdirs to be writable for the Tuning menu to work.
// Apart from `Resources` and resource groups, OGRE also keeps `Archives` in `ArchiveManager`
// These aren't unloaded on destroying resource groups, and keep a 'readOnly' flag (defaults to true).
// Upon loading/creating new resource groups, OGRE complains (=assert on Debug, exception on Release) if the submitted flag doesn't match.
// It's possible to manually unload archives to reset the flag, but for simplicity we just always load subdirs as 'writable', even during modcache update.
// ------------------------------------------------------------------------------------------

ResourceGroupManager::getSingleton().addResourceLocation(
Expand Down Expand Up @@ -295,7 +301,7 @@ void ContentManager::InitModCache(CacheValidity validity)
if (!dir_fileinfo.archive)
continue;
String fullpath = PathCombine(dir_fileinfo.archive->getName(), dir_fileinfo.filename);
ResourceGroupManager::getSingleton().addResourceLocation(fullpath, "FileSystem", RGN_CONTENT);
ResourceGroupManager::getSingleton().addResourceLocation(fullpath, "FileSystem", RGN_CONTENT, /*recursive:*/false, /*readonly:*/false);
}
ResourceGroupManager::getSingleton().destroyResourceGroup(RGN_TEMP);

Expand All @@ -308,19 +314,6 @@ void ContentManager::InitModCache(CacheValidity validity)
App::GetCacheSystem()->LoadModCache(validity);

ResourceGroupManager::getSingleton().destroyResourceGroup(RGN_CONTENT);

// Apart from `Resources` and resource groups, OGRE also keeps `Archives` in `ArchiveManager`
// These aren't unloaded on destroying resource groups, and keep a 'readOnly' flag (defaults to true).
// Upon loading/creating new resource groups, OGRE complains if the submitted flag doesn't match.
// Since we want to make subdirs (with upacked mods) writable, we must purge subdir-archives now.

for (const auto& dir_fileinfo : *dirs)
{
if (!dir_fileinfo.archive)
continue;
String fullpath = PathCombine(dir_fileinfo.archive->getName(), dir_fileinfo.filename);
ArchiveManager::getSingleton().unload(fullpath);
}

}

Expand Down

0 comments on commit 5870b93

Please sign in to comment.