diff --git a/editor/src/main/com/mbrlabs/mundus/editor/Editor.kt b/editor/src/main/com/mbrlabs/mundus/editor/Editor.kt index 9a488a979..fb3673270 100644 --- a/editor/src/main/com/mbrlabs/mundus/editor/Editor.kt +++ b/editor/src/main/com/mbrlabs/mundus/editor/Editor.kt @@ -52,6 +52,7 @@ import net.mgsx.gltf.scene3d.shaders.PBRDepthShaderProvider import org.apache.commons.io.FileUtils import org.apache.commons.io.FilenameUtils import org.lwjgl.opengl.GL11 +import java.io.File /** * @author Marcus Brummer @@ -237,6 +238,14 @@ class Editor : Lwjgl3WindowAdapter(), ApplicationListener, var path = FileUtils.getUserDirectoryPath() path = FilenameUtils.concat(path, "MundusProjects") + // If the default project already exists, import it instead of recreate it. + // This can happen if the registry was deleted but the project folder was not. + val defaultProjectPath = FilenameUtils.concat(path, name) + val file = File(defaultProjectPath) + if (file.exists()) { + return projectManager.importProject(defaultProjectPath) + } + return projectManager.createProject(name, path) } diff --git a/editor/src/main/com/mbrlabs/mundus/editor/core/project/ProjectManager.java b/editor/src/main/com/mbrlabs/mundus/editor/core/project/ProjectManager.java index 7ef2c70fc..6f11012df 100644 --- a/editor/src/main/com/mbrlabs/mundus/editor/core/project/ProjectManager.java +++ b/editor/src/main/com/mbrlabs/mundus/editor/core/project/ProjectManager.java @@ -248,6 +248,13 @@ public ProjectContext importProject(String absolutePath) throws ProjectAlreadyIm UI.INSTANCE.toggleLoadingScreen(true, context.name); ref.setName(context.name); registry.getProjects().add(ref); + + // Set this import project as last opened to prevent NPE only + // if no project was opened before + if (registry.getLastProject() == null){ + registry.setLastProject(ref); + } + kryoManager.saveRegistry(registry); startAsyncProjectLoad(absolutePath, context); return context; @@ -316,6 +323,14 @@ public void saveProject(ProjectContext projectContext) { public ProjectContext loadLastProjectAsync() { ProjectRef lastOpenedProject = registry.getLastOpenedProject(); if (lastOpenedProject != null) { + + // Check if file exists first + File file = new File(lastOpenedProject.getPath()); + if (!file.exists()) { + Log.error(TAG, "Last opened project does not exist: " + lastOpenedProject.getPath()); + return null; + } + try { return startAsyncProjectLoad(lastOpenedProject); } catch (FileNotFoundException fnf) {