Skip to content

Commit

Permalink
Merge pull request #62729 from m4gr3d/fix_save_scene_crash_bug_3x
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored Jul 5, 2022
2 parents 0cc154b + 27b6324 commit 917f215
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
4 changes: 4 additions & 0 deletions platform/android/export/export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ void EditorExportPlatformAndroid::_check_for_changes_poll_thread(void *ud) {
}
}

#ifndef ANDROID_ENABLED
// Check for devices updates
String adb = get_adb_path();
if (FileAccess::exists(adb)) {
Expand Down Expand Up @@ -372,6 +373,7 @@ void EditorExportPlatformAndroid::_check_for_changes_poll_thread(void *ud) {

ea->device_lock.unlock();
}
#endif

uint64_t sleep = 300'000;
uint64_t wait = 3'000'000;
Expand All @@ -384,6 +386,7 @@ void EditorExportPlatformAndroid::_check_for_changes_poll_thread(void *ud) {
}
}

#ifndef ANDROID_ENABLED
if (EditorSettings::get_singleton()->get("export/android/shutdown_adb_on_exit")) {
String adb = get_adb_path();
if (!FileAccess::exists(adb)) {
Expand All @@ -394,6 +397,7 @@ void EditorExportPlatformAndroid::_check_for_changes_poll_thread(void *ud) {
args.push_back("kill-server");
OS::get_singleton()->execute(adb, args, true);
}
#endif
}

String EditorExportPlatformAndroid::get_project_name(const String &p_name) const {
Expand Down
9 changes: 8 additions & 1 deletion platform/android/file_access_filesystem_jandroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,14 @@ Error FileAccessFilesystemJAndroid::_open(const String &p_path, int p_mode_flags
env->DeleteLocalRef(js);

if (res <= 0) {
return ERR_FILE_CANT_OPEN;
switch (res) {
case 0:
default:
return ERR_FILE_CANT_OPEN;

case -1:
return ERR_FILE_NOT_FOUND;
}
}

id = res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import android.content.Context
import android.util.Log
import android.util.SparseArray
import org.godotengine.godot.io.StorageScope
import java.io.FileNotFoundException
import java.nio.ByteBuffer

/**
Expand All @@ -44,6 +45,7 @@ class FileAccessHandler(val context: Context) {
companion object {
private val TAG = FileAccessHandler::class.java.simpleName

private const val FILE_NOT_FOUND_ERROR_ID = -1
private const val INVALID_FILE_ID = 0
private const val STARTING_FILE_ID = 1

Expand Down Expand Up @@ -104,6 +106,8 @@ class FileAccessHandler(val context: Context) {

files.put(++lastFileId, dataAccess)
return lastFileId
} catch (e: FileNotFoundException) {
return FILE_NOT_FOUND_ERROR_ID
} catch (e: Exception) {
Log.w(TAG, "Error while opening $path", e)
return INVALID_FILE_ID
Expand Down
27 changes: 27 additions & 0 deletions platform/android/os_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,33 @@ String OS_Android::get_system_dir(SystemDir p_dir, bool p_shared_storage) const
return godot_io_java->get_system_dir(p_dir, p_shared_storage);
}

Error OS_Android::move_to_trash(const String &p_path) {
DirAccessRef da_ref = DirAccess::create_for_path(p_path);
if (!da_ref) {
return FAILED;
}

// Check if it's a directory
if (da_ref->dir_exists(p_path)) {
Error err = da_ref->change_dir(p_path);
if (err) {
return err;
}
// This is directory, let's erase its contents
err = da_ref->erase_contents_recursive();
if (err) {
return err;
}
// Remove the top directory
return da_ref->remove(p_path);
} else if (da_ref->file_exists(p_path)) {
// This is a file, let's remove it.
return da_ref->remove(p_path);
} else {
return FAILED;
}
}

void OS_Android::set_offscreen_gl_available(bool p_available) {
secondary_gl_available = p_available;
}
Expand Down
2 changes: 2 additions & 0 deletions platform/android/os_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ class OS_Android : public OS_Unix {

virtual String get_system_dir(SystemDir p_dir, bool p_shared_storage = true) const;

virtual Error move_to_trash(const String &p_path);

void process_accelerometer(const Vector3 &p_accelerometer);
void process_gravity(const Vector3 &p_gravity);
void process_magnetometer(const Vector3 &p_magnetometer);
Expand Down

0 comments on commit 917f215

Please sign in to comment.