Skip to content

Commit

Permalink
Merge branch 'concurrent-task-prevention' into progress-bar
Browse files Browse the repository at this point in the history
  • Loading branch information
denneyl2711 committed Aug 7, 2024
2 parents 731859e + 2cb1272 commit 7d28a90
Show file tree
Hide file tree
Showing 16 changed files with 133 additions and 47 deletions.
5 changes: 5 additions & 0 deletions src/kintsugi3d/builder/app/Rendering.java
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,11 @@ public void warn(Throwable e)
{
ioModel.getProgressMonitor().warn(e);
}

@Override
public boolean isConflictingProcess() {
return ioModel.getProgressMonitor().isConflictingProcess();
}
});

app.addRefreshable(new Refreshable()
Expand Down
5 changes: 5 additions & 0 deletions src/kintsugi3d/builder/core/DefaultProgressMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@ public void complete()
public void fail(Throwable e)
{
}

@Override
public boolean isConflictingProcess() {
return false;
}
}
35 changes: 12 additions & 23 deletions src/kintsugi3d/builder/core/IBRRequestManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,20 @@

package kintsugi3d.builder.core;

import java.util.LinkedList;
import java.util.Queue;

import javafx.scene.control.*;
import kintsugi3d.builder.javafx.controllers.menubar.MenubarController;
import kintsugi3d.gl.interactive.GraphicsRequest;
import javafx.application.Platform;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import kintsugi3d.builder.javafx.ProjectIO;
import kintsugi3d.builder.rendering.IBRInstanceManager;
import kintsugi3d.gl.core.Context;
import kintsugi3d.gl.interactive.GraphicsRequest;
import kintsugi3d.gl.interactive.ObservableGraphicsRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.LinkedList;
import java.util.Queue;

public class IBRRequestManager<ContextType extends Context<ContextType>> implements IBRRequestQueue<ContextType>
{
private static final Logger log = LoggerFactory.getLogger(IBRRequestManager.class);
Expand Down Expand Up @@ -112,6 +108,10 @@ public synchronized void addBackgroundIBRRequest(IBRRequest request)
@Override
public synchronized void addIBRRequest(ObservableIBRRequest request)
{
if(this.progressMonitor.isConflictingProcess()){
return;
}

if (instanceManager.getLoadedInstance() == null)
{
// Instance is currently null, wait for a load and then call this function again (recursive-ish)
Expand Down Expand Up @@ -148,21 +148,7 @@ public synchronized void addIBRRequest(ObservableIBRRequest request)
}
catch (Exception | AssertionError e)
{
log.error("Error occurred while executing request:", e);
Platform.runLater(() ->
{
ButtonType ok = new ButtonType("OK", ButtonBar.ButtonData.CANCEL_CLOSE);
ButtonType showLog = new ButtonType("Show Log", ButtonBar.ButtonData.YES);
Alert alert = new Alert(Alert.AlertType.NONE,
"An error occurred processing request. Processing has stopped\nSee the log for more info.",
ok, showLog);

((ButtonBase) alert.getDialogPane().lookupButton(showLog)).setOnAction(event -> {
// Use the menubar's console open function to prevent 2 console windows from appearing
MenubarController.getInstance().help_console();
});
alert.show();
});
ProjectIO.handleException("Error occured while excecuting request", e);
}
}

Expand Down Expand Up @@ -209,6 +195,9 @@ public synchronized void addGraphicsRequest(ObservableGraphicsRequest request)
{
if (progressMonitor != null)
{
if(this.progressMonitor.isConflictingProcess()){
return;
}
progressMonitor.start();
}

Expand Down
13 changes: 13 additions & 0 deletions src/kintsugi3d/builder/core/IOModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@ public void warn(Throwable e)
monitor.warn(e);
}
}

@Override
public boolean isConflictingProcess() {
boolean processing = false;
for (ProgressMonitor monitor : subMonitors)
{
if(monitor.isConflictingProcess()){
processing = true;
}
}

return processing;
}
}

private IOHandler handler;
Expand Down
7 changes: 7 additions & 0 deletions src/kintsugi3d/builder/core/ProgressMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,11 @@ public interface ProgressMonitor
default void warn(Throwable e)
{
}

/**
* Usually a call to ProgressBarsController.getInstance().isProcessing().
* Used to stop multiple processes from conflicting with each other.
* @return true if a process is in progress.
*/
boolean isConflictingProcess();
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import javafx.stage.FileChooser.ExtensionFilter;
import javafx.stage.Stage;
import javafx.stage.Window;
import kintsugi3d.builder.javafx.MultithreadModels;
import kintsugi3d.util.RecentProjects;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -136,6 +137,10 @@ public <ContextType extends Context<ContextType>> void prompt(IBRRequestQueue<Co
{
// stage.close();

if(MultithreadModels.getInstance().getIOModel().getProgressMonitor().isConflictingProcess()){
return;
}

File fragmentShader = new File(fragmentShaderField.getText());
File outputDirectory = new File(exportDirectoryField.getText());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import kintsugi3d.builder.core.*;
import kintsugi3d.builder.fit.settings.ExportSettings;

import kintsugi3d.builder.javafx.MultithreadModels;
import kintsugi3d.builder.util.Kintsugi3DViewerLauncher;
import kintsugi3d.gl.core.Context;
import org.slf4j.Logger;
Expand Down Expand Up @@ -103,6 +104,10 @@ public <ContextType extends Context<ContextType>> void prompt(IBRRequestQueue<Co
//Updates settings to equal what widget is displaying
saveAllVariables(settings);

if(MultithreadModels.getInstance().getIOModel().getProgressMonitor().isConflictingProcess()){
return;
}

try
{
exportLocationFile = objFileChooser.showSaveDialog(stage);
Expand Down
5 changes: 5 additions & 0 deletions src/kintsugi3d/builder/export/resample/ResampleRequestUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import javafx.stage.FileChooser.ExtensionFilter;
import javafx.stage.Stage;
import javafx.stage.Window;
import kintsugi3d.builder.javafx.MultithreadModels;
import kintsugi3d.gl.core.Context;
import kintsugi3d.builder.core.IBRRequestQueue;
import kintsugi3d.builder.core.IBRRequestUI;
Expand Down Expand Up @@ -126,6 +127,10 @@ public <ContextType extends Context<ContextType>> void prompt(IBRRequestQueue<Co
{
//stage.close();

if(MultithreadModels.getInstance().getIOModel().getProgressMonitor().isConflictingProcess()){
return;
}

requestQueue.addIBRRequest(
new ResampleRequest(
Integer.parseInt(widthTextField.getText()),
Expand Down
5 changes: 5 additions & 0 deletions src/kintsugi3d/builder/export/screenshot/ScreenshotUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javafx.stage.FileChooser.ExtensionFilter;
import javafx.stage.Stage;
import javafx.stage.Window;
import kintsugi3d.builder.javafx.MultithreadModels;
import kintsugi3d.gl.core.Context;
import kintsugi3d.builder.core.IBRRequestQueue;
import kintsugi3d.builder.core.IBRRequestUI;
Expand Down Expand Up @@ -115,6 +116,10 @@ public <ContextType extends Context<ContextType>> void prompt(IBRRequestQueue<Co
//stage.close();
if (builderSupplier != null)
{
if(MultithreadModels.getInstance().getIOModel().getProgressMonitor().isConflictingProcess()){
return;
}

requestQueue.addIBRRequest(
builderSupplier.get()
.setWidth(Integer.parseInt(widthTextField.getText()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javafx.stage.DirectoryChooser;
import javafx.stage.Stage;
import javafx.stage.Window;
import kintsugi3d.builder.javafx.MultithreadModels;
import kintsugi3d.gl.core.Context;
import kintsugi3d.builder.core.IBRRequestQueue;
import kintsugi3d.builder.core.IBRRequestUI;
Expand Down Expand Up @@ -109,6 +110,10 @@ public <ContextType extends Context<ContextType>> void prompt(IBRRequestQueue<Co
//stage.close();
if (builderSupplier != null)
{
if(MultithreadModels.getInstance().getIOModel().getProgressMonitor().isConflictingProcess()){
return;
}

requestQueue.addIBRRequest(
builderSupplier.get()
.setWidth(Integer.parseInt(widthTextField.getText()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import kintsugi3d.builder.fit.SpecularFitProcess;
import kintsugi3d.builder.fit.SpecularFitProgramFactory;
import kintsugi3d.builder.fit.settings.SpecularFitRequestParams;
import kintsugi3d.builder.javafx.ProjectIO;
import kintsugi3d.builder.javafx.controllers.menubar.MenubarController;
import kintsugi3d.builder.metrics.ColorAppearanceRMSE;
import kintsugi3d.builder.resources.ibr.ReadonlyIBRResources;
Expand Down Expand Up @@ -105,7 +106,7 @@ public <ContextType extends Context<ContextType>> void executeRequest(IBRInstanc
}
catch(IOException e) // thrown by createReflectanceProgram
{
log.error("Error executing specular fit request:", e);
ProjectIO.handleException("Error executing specular fit request:", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import kintsugi3d.builder.core.Kintsugi3DBuilderState;
import kintsugi3d.builder.core.TextureResolution;
import kintsugi3d.builder.fit.settings.SpecularFitRequestParams;
import kintsugi3d.builder.javafx.MultithreadModels;
import kintsugi3d.gl.core.Context;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -111,6 +112,10 @@ public <ContextType extends Context<ContextType>> void prompt(IBRRequestQueue<Co
{
//stage.close();

if(MultithreadModels.getInstance().getIOModel().getProgressMonitor().isConflictingProcess()){
return;
}

SpecularFitRequestParams settings = new SpecularFitRequestParams(new TextureResolution(
Integer.parseInt(widthTextField.getText()),
Integer.parseInt(heightTextField.getText())),
Expand Down
12 changes: 7 additions & 5 deletions src/kintsugi3d/builder/javafx/ProjectIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@
import kintsugi3d.builder.javafx.controllers.scene.ProgressBarsController;
import kintsugi3d.builder.javafx.controllers.scene.WelcomeWindowController;
import kintsugi3d.builder.resources.ibr.MeshImportException;
import kintsugi3d.gl.interactive.InteractiveRenderable;
import kintsugi3d.gl.interactive.InteractiveRenderableList;
import kintsugi3d.util.Flag;
import kintsugi3d.util.RecentProjects;
import org.slf4j.Logger;
Expand Down Expand Up @@ -119,8 +117,7 @@ public void fail(Throwable e)
projectLoaded = false;
if (e instanceof MeshImportException)
{
//TODO: change to (e.getMessage(), e)?
handleException("Imported object is missing texture coordinates", e);
handleException(e.getMessage(), e);
}
else
{
Expand Down Expand Up @@ -151,7 +148,7 @@ public boolean isProjectLoaded()
return projectLoaded;
}

private static void handleException(String message, Throwable e)
public static void handleException(String message, Throwable e)
{
log.error("{}:", message, e);
Platform.runLater(() ->
Expand Down Expand Up @@ -375,6 +372,11 @@ private static void startLoad(File projectFile, File vsetFile)

public void openProjectFromFile(File selectedFile)
{
//need to check for conflicting process early so crucial info isn't unloaded
if(MultithreadModels.getInstance().getIOModel().getProgressMonitor().isConflictingProcess()){
return;
}

//open the project, update the recent files list & recentDirectory, disable shaders which aren't useful until processing textures
this.projectFile = selectedFile;
RecentProjects.setMostRecentDirectory(this.projectFile.getParentFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;

import static kintsugi3d.builder.javafx.ProjectIO.handleException;

public class MenubarController
{
private static final Logger log = LoggerFactory.getLogger(MenubarController.class);
Expand Down Expand Up @@ -286,9 +288,6 @@ public void cancelComplete(UserCancellationException e)
@Override
public void start()
{
//TODO: deal with conflicting processes here
//if process is already happening, cancel it and continue with the new one?

cancelRequested.set(false);

stageCountProperty.setValue(0);
Expand Down Expand Up @@ -431,6 +430,36 @@ public void fail(Throwable e)
{
complete();
}

@Override
public boolean isConflictingProcess(){
if (!ProgressBarsController.getInstance().isProcessing()){
return false;
}

Platform.runLater(() ->
{
ButtonType ok = new ButtonType("OK", ButtonBar.ButtonData.OK_DONE);
//ButtonType stopProcess = new ButtonType("Start New Process", ButtonBar.ButtonData.YES);
Alert alert = new Alert(AlertType.NONE, "Cannot run multiple tasks at the same time.\n" +
"Either wait for the current task to complete or cancel it." /*+
"Press OK to finish the current process."*/, ok/*, stopProcess*/);
alert.setHeaderText("Conflicting Tasks");

// //continue current process, don't start a new one
// ((Button) alert.getDialogPane().lookupButton(ok)).setOnAction(event -> {
// });
//
// //cancel current process and start new one
// ((Button) alert.getDialogPane().lookupButton(stopProcess)).setOnAction(event -> {
// cancelRequested.set(true);
// });

alert.showAndWait();
});

return true;
}
});

boolean foundExportClass = false;
Expand Down Expand Up @@ -1023,21 +1052,6 @@ public void launchViewerApp()
}
}

private void handleException(String message, Exception e)
{
log.error("{}:", message, e);
Platform.runLater(() ->
{
ButtonType ok = new ButtonType("OK", ButtonBar.ButtonData.OK_DONE);
ButtonType showLog = new ButtonType("Show Log", ButtonBar.ButtonData.YES);
Alert alert = new Alert(AlertType.ERROR, message + "\nSee the log for more info.", ok, showLog);
((Button) alert.getDialogPane().lookupButton(showLog)).setOnAction(event -> {
help_console();
});
alert.show();
});
}

public void file_removeInvalidReferences() {
RecentProjects.removeInvalidReferences();
}
Expand Down
Loading

0 comments on commit 7d28a90

Please sign in to comment.