diff options
author | Thanasis Antoniou | 2019-12-16 22:58:26 +0200 |
---|---|---|
committer | Thanasis Antoniou | 2019-12-16 22:59:10 +0200 |
commit | 0357293897ad80eb549e63952551c1781ad41b95 (patch) | |
tree | 3dbed6e83093dcd19760227aa87091ed53df41ed /backends | |
parent | 4b2591b5c935bf5a2835cbfd10ac4202bb23e81b (diff) | |
download | scummvm-rg350-0357293897ad80eb549e63952551c1781ad41b95.tar.gz scummvm-rg350-0357293897ad80eb549e63952551c1781ad41b95.tar.bz2 scummvm-rg350-0357293897ad80eb549e63952551c1781ad41b95.zip |
ANDROID: Fix crash due to adding '.' folder in SearchManager
Diffstat (limited to 'backends')
-rw-r--r-- | backends/fs/posix/posix-fs-factory.cpp | 14 | ||||
-rw-r--r-- | backends/platform/android/asset-archive.cpp | 3 |
2 files changed, 17 insertions, 0 deletions
diff --git a/backends/fs/posix/posix-fs-factory.cpp b/backends/fs/posix/posix-fs-factory.cpp index 94959921f3..e0eebbdbaf 100644 --- a/backends/fs/posix/posix-fs-factory.cpp +++ b/backends/fs/posix/posix-fs-factory.cpp @@ -41,8 +41,22 @@ AbstractFSNode *POSIXFilesystemFactory::makeRootFileNode() const { } AbstractFSNode *POSIXFilesystemFactory::makeCurrentDirectoryFileNode() const { +#if defined(__ANDROID__) + // For Android it does not make sense to have "." in Search Manager as a current directory file node, so we skip it here + // Otherwise this can potentially lead to a crash since, in Android getcwd() returns the root path "/" + // and when SearchMan is used (eg. SearchSet::createReadStreamForMember) and it tries to search root path (and calls POSIXFilesystemNode::getChildren()) + // then a JNI call is made (JNI::getAllStorageLocations()) which leads to a crash if done from the wrong context -- and is also useless overhead as a call in that case. + // This fixes the error case: Loading "Beneath A Steel Sky" with Adlib or FluidSynth audio once, exiting to Launcher via in-game ScummVM menu and re-launching the game. + // Don't return NULL here, since it causes crash with other engines (eg. Blade Runner) + // Returning '.' here will cause POSIXFilesystemNode::getChildren() to ignore it + // + // We also skip adding the '.' directory to SearchManager (in archive.cpp, SearchManager::clear()) + char buf[MAXPATHLEN] = {'.', '\0'}; + return new POSIXFilesystemNode(buf); +#else char buf[MAXPATHLEN]; return getcwd(buf, MAXPATHLEN) ? new POSIXFilesystemNode(buf) : NULL; +#endif } AbstractFSNode *POSIXFilesystemFactory::makeFileNodePath(const Common::String &path) const { diff --git a/backends/platform/android/asset-archive.cpp b/backends/platform/android/asset-archive.cpp index 44e5ed80f2..255262d309 100644 --- a/backends/platform/android/asset-archive.cpp +++ b/backends/platform/android/asset-archive.cpp @@ -71,6 +71,9 @@ AssetInputStream::AssetInputStream(AAssetManager *as, const Common::String &path } AssetInputStream::~AssetInputStream() { + if (_asset != NULL) { + AAsset_close(_asset); + } } void AssetInputStream::close() { |