aboutsummaryrefslogtreecommitdiff
path: root/backends/fs/posix/posix-fs-factory.cpp
diff options
context:
space:
mode:
authorThanasis Antoniou2019-12-16 22:58:26 +0200
committerThanasis Antoniou2019-12-16 22:59:10 +0200
commit0357293897ad80eb549e63952551c1781ad41b95 (patch)
tree3dbed6e83093dcd19760227aa87091ed53df41ed /backends/fs/posix/posix-fs-factory.cpp
parent4b2591b5c935bf5a2835cbfd10ac4202bb23e81b (diff)
downloadscummvm-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/fs/posix/posix-fs-factory.cpp')
-rw-r--r--backends/fs/posix/posix-fs-factory.cpp14
1 files changed, 14 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 {