Looks to me like you are using the same JmolViewer object for both frames. You have to use independent JmolViewer objects -- there are two threads there going on at the same time apparently using the same JmolViewer instance. Is that possible?

Bob


On Tue, Feb 17, 2009 at 12:46 AM, Anubhav Jain <anubhavj@mit.edu> wrote:
Dear Bob,

Thank you for your extremely prompt response.  Based on your
suggestion, I made a few code modifications.  I am using Jmol 11.6 now
(I had some trouble using 11.7).  I overrode the dispose() method of
my frame so that it would call
viewer.setModeMouse(JmolConstants.MOUSE_NONE) before calling
super.dispose().  I also changed the way the viewer loaded the
structure.  This has fixed the memory leak (!!), but unfortunately has
caused some other strange behavior in which opening multiple frames
(with multiple JmolViewers) give errors.

The first two lines in my new code are:
           JmolViewer viewer = jmolPanel.getViewer();
           viewer.evalString("ZAP");
where viewer is a JmolViewer that has previously been initialized
using viewer=new JmolViewer();  jmolPanel is an instance of JmolPanel,
the code for which is appended to the end of this e-mail.

Depending on the third line I put after these two lines, I get
different behaviors:
--------------------------------------------------------------------
********************************************
if 3rd line=: viewer.openStringInline(<cif string>);
********************************************
In this case, the first frame I open up loads the CIF fine and the
frame shows the Jmol panel.  However, if I attempt to open a second or
third frame I get an error.  Therefore, only the first frame I load
seems to work.  The error I get is reproduced below (apologies for not
having line numbers in the error messages, I'm so far working with
just the Jmol .jar):

FileManager.openStringInline()
The Resolver thinks Cif
ModelSet: haveSymmetry:true haveUnitcells:true haveFractionalCoord:true
1 model in this collection. Use getProperty "modelInfo" or getProperty
"auxiliaryInfo" to inspect them.
ModelSet: autobonding; use  autobond=false  to not generate bonds automatically
FileManager.openStringInline()
The Resolver thinks Cif
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
       at org.jmol.viewer.Viewer.getCurrentUnitCell(Unknown Source)
       at org.jmol.modelset.ModelCollection.getAtomBits(Unknown Source)
       at org.jmol.modelset.ModelSet.getAtomBits(Unknown Source)
       at org.jmol.modelset.ModelLoader.initializeUnitCellAndSymmetry(Unknown Source)
       at org.jmol.modelset.ModelLoader.initializeModelSet(Unknown Source)
       at org.jmol.modelset.ModelLoader.<init>(Unknown Source)
       at org.jmol.viewer.ModelManager.setClientFile(Unknown Source)
       at org.jmol.viewer.Viewer.openClientFile(Unknown Source)ModelSet:
haveSymmetry:true haveUnitcells:true haveFractionalCoord:true
1 model in this collection. Use getProperty "modelInfo" or getProperty
"auxiliaryInfo" to inspect them.

       at org.jmol.viewer.Viewer.getOpenFileError(Unknown Source)
       at org.jmol.viewer.Viewer.openStringInline(Unknown Source)
       at org.jmol.viewer.Viewer.openStringInline(Unknown Source)
       at com.cmcweb.db.postgresql.DetailsGUI.init(DetailsGUI.java:403)
       at com.cmcweb.db.postgresql.DetailsGUI.doVis(DetailsGUI.java:161)
       at com.cmcweb.visualizer.EntryDetailsVisualizer.doVis(EntryDetailsVisualizer.java:30)
       at com.cmcweb.db.postgresql.DBQueryGUI.showDetails(DBQueryGUI.java:637)
       at com.cmcweb.db.postgresql.DBQueryGUI$2.mouseClicked(DBQueryGUI.java:1014)
       at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
       at java.awt.Component.processMouseEvent(Unknown Source)
       at javax.swing.JComponent.processMouseEvent(Unknown Source)
       at java.awt.Component.processEvent(Unknown Source)
       at java.awt.Container.processEvent(Unknown Source)
       at java.awt.Component.dispatchEventImpl(Unknown Source)
       at java.awt.Container.dispatchEventImpl(Unknown Source)
       at java.awt.Component.dispatchEvent(Unknown Source)
       at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
       at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
       at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
       at java.awt.Container.dispatchEventImpl(Unknown Source)
       at java.awt.Window.dispatchEventImpl(Unknown Source)
       at java.awt.Component.dispatchEvent(Unknown Source)
       at java.awt.EventQueue.dispatchEvent(Unknown Source)
       at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
       at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
       at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
       at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
       at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
       at java.awt.EventDispatchThread.run(Unknown Source)

********************************************
if 3rd line=: viewer.openFile("temp.cif");
********************************************
Sometimes, multiple frames can be opened without a problem.  Other
times I get the following error.  There does not seem to be any
pattern as to when another frame can be opened without problems, and
when it gives an error.

FileManager.openFile(temp.cif) //temp.cif
FileManager opening C:\cygwin\home\Anubhav\src\java\jcmc\temp.cif
The Resolver thinks Cif
openFile(temp.cif): 0 ms
ModelSet: haveSymmetry:true haveUnitcells:true haveFractionalCoord:true
1 model in this collection. Use getProperty "modelInfo" or getProperty
"auxiliaryInfo" to inspect them.
ModelSet: autobonding; use  autobond=false  to not generate bonds automatically
Exception in thread "QueueThread0" java.lang.NullPointerException
       at org.jmol.viewer.Viewer.getModelCount(Unknown Source)
       at org.jmol.viewer.Eval.load(Unknown Source)
       at org.jmol.viewer.Eval.instructionDispatchLoop(Unknown Source)
       at org.jmol.viewer.Eval.runEval(Unknown Source)
       at org.jmol.viewer.Viewer.evalStringWaitStatus(Unknown Source)
       at org.jmol.viewer.ScriptManager$ScriptQueueRunnable.runScript(Unknown Source)
       at org.jmol.viewer.ScriptManager$ScriptQueueRunnable.runNextScript(Unknown
Source)
FileManager opening temp.cif
       at org.jmol.viewer.ScriptManager$ScriptQueueRunnable.run(Unknown Source)
       at java.lang.Thread.run(Unknown Source)

********************************************
if 3rd line=: viewer.evalString("data \"model\"\n" + <cif string> +
"\nend \"model\"\n");
********************************************
This does not work at all, although <cif string> is the same CIF
string given in the first case.  Perhaps my syntax is wrong?  The
error here reads:
FileManager.openStringInline()
The Resolver thinks Cif
Exception in thread "QueueThread0"
java.lang.NullPointerExceptionModelSet: haveSymmetry:true
haveUnitcells:true haveFractionalCoord:true
1 model in this collection. Use getProperty "modelInfo" or getProperty
"auxiliaryInfo" to inspect them.

       at org.jmol.viewer.Viewer.getCurrentUnitCell(Unknown Source)
       at org.jmol.modelset.ModelCollection.getAtomBits(Unknown Source)
       at org.jmol.modelset.ModelSet.getAtomBits(Unknown Source)
       at org.jmol.modelset.ModelLoader.initializeUnitCellAndSymmetry(Unknown Source)
       at org.jmol.modelset.ModelLoader.initializeModelSet(Unknown Source)
       at org.jmol.modelset.ModelLoader.<init>(Unknown Source)
       at org.jmol.viewer.ModelManager.setClientFile(Unknown Source)
       at org.jmol.viewer.Viewer.openClientFile(Unknown Source)
       at org.jmol.viewer.Viewer.getOpenFileError(Unknown Source)
       at org.jmol.viewer.Viewer.openStringInline(Unknown Source)
       at org.jmol.viewer.Viewer.loadInline(Unknown Source)
       at org.jmol.viewer.Eval.data(Unknown Source)
       at org.jmol.viewer.Eval.instructionDispatchLoop(Unknown Source)
       at org.jmol.viewer.Eval.runEval(Unknown Source)
       at org.jmol.viewer.Viewer.evalStringWaitStatus(Unknown Source)
       at org.jmol.viewer.ScriptManager$ScriptQueueRunnable.runScript(Unknown Source)
       at org.jmol.viewer.ScriptManager$ScriptQueueRunnable.runNextScript(Unknown
Source)
       at org.jmol.viewer.ScriptManager$ScriptQueueRunnable.run(Unknown Source)
       at java.lang.Thread.run(Unknown Source)

----------------------------------------------

I'm confused as to why loading the file in different ways leads to
different behaviors.  The goal is to be able to load multiple frames,
each with their own independent JmolViewer / JmolPanel objects.

Thank you again for your help (I'm glad to be past the memory leak problem!).

Best,
Anubhav


The code I'm using for JmolPanel is appended below [taken from
Integration.java example]:
package com.cmcweb.db.postgresql;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Rectangle;

import javax.swing.*;
import org.jmol.adapter.smarter.SmarterJmolAdapter;
import org.jmol.api.JmolAdapter;
import org.jmol.api.JmolViewer;

public class JmolPanel extends JPanel {
   JmolViewer viewer;
   JmolAdapter adapter;
   JmolPanel() {
     adapter = new SmarterJmolAdapter();
     viewer = JmolViewer.allocateViewer(this, adapter);
   }

   public JmolViewer getViewer() {
     return viewer;
   }

   final Dimension currentSize = new Dimension();
   final Rectangle rectClip = new Rectangle();

   public void paint(Graphics g) {
     getSize(currentSize);
     g.getClipBounds(rectClip);
     viewer.renderScreenImage(g, currentSize, rectClip);
   }
 }




On Mon, Feb 16, 2009 at 10:01 PM, Robert Hanson <hansonr@stolaf.edu> wrote:
> Frankly, I can't help you with 11.2. That was so long ago, and the code has
> changed so much, who knows what bug that could be. So this discussion
> assumes at least 11.6; I'm using 11.7. I don't think you can use
> JmolSimpleViewer for these purposes. Any particular reason you are using
> that rather than JmolViewer itself? JmolViewer includes a method,
> setModeMouse(int mode) that allows you to close out the viewer and start a
> new one; JmolSimpleViewer does not.
>
>   /**
>    * NOTE: for APPLICATION AND APPLET call
>    *
>    *   setModeMouse(JmolConstants.MOUSE_NONE);
>    *
>    * before setting viewer=null
>    *
>    * in order to remove references to display window in listeners and
> hoverWatcher
>
>
> Failure to do that will certainly cause the effect you describe.
>
> As for openStringInline(), that should work fine. But the sequence you
> describe really should not work:
>
>            viewer.openStringInline("<cif string>", true));
>            viewer.evalString(strScript);
>            String strError = viewer.getOpenFileError();
>
>
> The first creates a model, the second adds a script to a queue, and the
> third -- well, here's the note I made to myself:
>
>   // The following was NOT what you think it was:
>   //   abstract public String getOpenFileError();
>   // Somewhere way back when, "openFile" became a method that did not create
>   // the model set, but just an intermediary AtomSetCollection called the
> "clientFile"
>   // (and did not necessarily close the file)
>   // then "getOpenFileError()" actually created the model set, deallocated
> the file open thread,
>   // and closed the file.
>
> That could be 11.2.... I took that out, because it should never be used, at
> least not in any recent version of Jmol.
>
> In Jmol 11.6 or 11.7 it's way easier than this. All you would need is:
>
>            viewer.evalString("data \"model\"\n" + cifString + "\nend
> \"model\"\n" + strScript);
>
> There should be no memory issues, provided you use
>
>    viewer.setModeMouse(JmolConstants.MOUSE_NONE);
>
> prior to disposing of the frame.
>
>
> Bob
>
> --
> Robert M. Hanson
> Professor of Chemistry
> St. Olaf College
> 1520 St. Olaf Ave.
> Northfield, MN 55057
> http://www.stolaf.edu/people/hansonr
> phone: 507-786-3107
>
>
> If nature does not answer first what we want,
> it is better to take what answer we get.
>
> -- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900
>
> ------------------------------------------------------------------------------
> Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
> -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
> -Strategies to boost innovation and cut costs with open source participation
> -Receive a $600 discount off the registration fee with the source code: SFAD
> http://p.sf.net/sfu/XcvMzF8H
> _______________________________________________
> Jmol-developers mailing list
> Jmol-developers@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jmol-developers
>
>

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Jmol-developers mailing list
Jmol-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-developers



--
Robert M. Hanson
Professor of Chemistry
St. Olaf College
1520 St. Olaf Ave.
Northfield, MN 55057
http://www.stolaf.edu/people/hansonr
phone: 507-786-3107


If nature does not answer first what we want,
it is better to take what answer we get.

-- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900