aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/fs/posix/posix-fs-factory.cpp14
-rw-r--r--backends/platform/android/asset-archive.cpp3
-rw-r--r--common/archive.cpp3
3 files changed, 20 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() {
diff --git a/common/archive.cpp b/common/archive.cpp
index 586f3c4fd1..ae89a9edcf 100644
--- a/common/archive.cpp
+++ b/common/archive.cpp
@@ -279,9 +279,12 @@ void SearchManager::clear() {
if (g_system)
g_system->addSysArchivesToSearchSet(*this, -1);
+#ifndef __ANDROID__
// Add the current dir as a very last resort.
// See also bug #2137680.
+ // But don't do this for Android platform, since it may lead to crashes
addDirectory(".", ".", -2);
+#endif
}
DECLARE_SINGLETON(SearchManager);