Skip to content

Commit

Permalink
Model Viewer: Fix invalid resource disposal on editor drag and drop
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadelessFox committed Aug 10, 2024
1 parent 6817106 commit d2968c9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class ModelViewport extends AWTGLCanvas implements Disposable {
private boolean softShading = true;

private OutlineDialog outlineDialog;
private Model model;

public ModelViewport(@NotNull Camera camera) {
super(createData());
Expand Down Expand Up @@ -112,6 +113,8 @@ public void initGL() {
} catch (IOException e) {
throw new UncheckedIOException(e);
}

modelRenderer.setModel(model);
}

@Override
Expand Down Expand Up @@ -162,25 +165,31 @@ public void paintGL() {
}

@Override
public void dispose() {
outlineRenderer.dispose();
gridRenderer.dispose();
modelRenderer.dispose();
debugRenderer.dispose();
public void removeNotify() {
if (initCalled) {
outlineRenderer.dispose();
gridRenderer.dispose();
modelRenderer.dispose();
debugRenderer.dispose();

glDisable(GL_DEBUG_OUTPUT);
glDisable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
glDebugMessageCallback(null, 0);
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, false);
}

super.removeNotify();
}

@Override
public void dispose() {
if (outlineDialog != null) {
outlineDialog.dispose();
outlineDialog = null;
}

if (!initCalled) {
return;
}

glDisable(GL_DEBUG_OUTPUT);
glDisable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
glDebugMessageCallback(null, 0);
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, false);
// Will be disposed in ModelRenderer#dispose()
model = null;
}

public boolean isShowOutline() {
Expand Down Expand Up @@ -224,14 +233,15 @@ public Camera getCamera() {

@Nullable
public Model getModel() {
return modelRenderer.getModel();
return model;
}

public void setModel(@Nullable Model model) {
final Model oldModel = modelRenderer.getModel();
final Model oldModel = this.model;

if (oldModel != model) {
modelRenderer.setModel(model);
this.model = model;
firePropertyChange("model", oldModel, model);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ public boolean isDataFlavorSupported(DataFlavor flavor) {
return tabFlavor.equals(flavor);
}

@NotNull
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
if (isDataFlavorSupported(flavor)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public SplitResult split(int orientation, double position, boolean leading) {

removeAll();
add(pane, BorderLayout.CENTER);
validate();
invalidate();

pane.setResizeWeight(position);
pane.setDividerLocation(position);
Expand All @@ -65,11 +65,9 @@ public void compact() {
leaf = container.getComponent(0);
}

if (leaf != null) {
if (leaf != null && getComponent(0) != leaf) {
removeAll();
add(leaf, BorderLayout.CENTER);

revalidate();
invalidate();
}

Expand Down

0 comments on commit d2968c9

Please sign in to comment.