We are about to switch to a new forum software. Until then we have removed the registration on this forum.
In my Project you can open multiple Files. For each File I want to show an UnfoldingMap Object in a JPanel (own Instance). When switching between files, the PApplet of the file, which no longer is shown, should by destroyed.
I´m able to show the PApplet, but when I switch to an other file, an Exception is thrown executing PApplet.destroy();
PApplettSubClass:
public class EmbeddedMap extends PApplet
{
public void setup()
{
size(getWidth(), getHeight(), OPENGL);
}
public void draw()
{
background(0);
}
}
Adding To Panel:
public void init(Object data)
{
CardLayout cl = new CardLayout();
JPanel panel = new JPanel(cl);
if (mapApp == null)
{
panel.add(getMapApp(), mapApp.getName());
cl.show( panel, mapApp.getName() );
}
}
Creating PApplet:
public EmbeddedMap getMapApp()
{
if (mapApp == null)
{
mapApp = new EmbeddedMap(cgService);
mapApp.setPreferredSize(new Dimension(500,200));
mapApp.init();
}
return mapApp;
}
Destroy / Remove from Panel:
public void pause()
{
if (mapApp != null)
{
mapApp.stop();
mapApp.destroy(); //Exception thrown...
panel.remove(mapApp);
mapApp = null;
System.gc();
}
}
Exception:
java.lang.NullPointerException
at jogamp.opengl.gl4.GL4bcImpl.glDeleteTextures(GL4bcImpl.java:4095)
at processing.opengl.PJOGL.deleteTextures(PJOGL.java:1977)
at processing.opengl.PGL.deleteSurface(PGL.java:374)
at processing.opengl.PJOGL.deleteSurface(PJOGL.java:423)
at processing.opengl.PGraphicsOpenGL.dispose(PGraphicsOpenGL.java:651)
at processing.core.PApplet.dispose(PApplet.java:4145)
at processing.core.PApplet.destroy(PApplet.java:1207)
Answers
http://forum.processing.org/two/discussion/8045/how-to-format-code-and-text
http://forum.processing.org/two/discussion/11242/unintentional-closing-and-wrong-size-if-setvisible-false-problem-of-second-window-with-jframe
Thank You for the formatting hints. My Question maybe was to unspecific. I want to know, how I can detroy an PApplet inside a JFrame/JPanel. The link You posted is about show/hide/resize an PApplet.
I avoided the Exception by using the Java2D Renderer instead OpenGL. But if I destroy the PApplet Object the memory is not completely released. So my Application grows and grows...
I dunno how to cleanly destroy a specific PApplet w/o memory leakage either.
Our best shot is show()/hide() & loop()/noLoop() the PApplet we want to.
And indeed, for multiple PApplet, only 1 non-JAVA2D at most is allowed.