Skip to main content

JSGPanelRepainter bug

1 reply [Last post]
mortennobel
Offline
Joined: 2004-11-03
Points: 0

There seems to be a rather nasty bug with JavaSceneGraph and applets. When you reload an applet containing a JSGPanel it is no longer repainted correctly. So if the JSGPanel do anything visual after being displayed the second time, the applet will appear frozen (actually it isn’t – but it is no longer repainted).

There is a problem with the JSGPanelRepainter. Currently the JSGPanelRepainter class is a singleton that registers itself when the class is loaded the first time (after a repaint request from the first time applet is loaded). The second time the applet get’s loaded, the JSGPanelRepainter-instance does not register itself – and is actually not active at this point.

A simple testcase that shows the problem (Run the applet from a real browser to see the problem):
_______________ JSGPanelTest.java start ____________________
public class JSGPanelTest extends JApplet {
public void init() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
setLayout(new BorderLayout());
JSGPanel panel = new JSGPanel();
final SGShape node = new SGShape();
node.setShape(new Rectangle(10,10,50,50));
node.setFillPaint(Color.red);
Clip clip = Clip.create(1000,new TimingTargetAdapter(){
Evaluator colorEvaluator = Evaluators.getLinearInstance(Color.class);
public void timingEvent(float fraction, long totalElapsed) {
node.setFillPaint(colorEvaluator.evaluate(Color.red, Color.black, fraction));
}
});
final MouseTrigger mouseTrigger = new MouseTrigger(clip, MouseTriggerEvent.ENTER);
clip.setAutoReverse(true);
node.addMouseListener(new SGMouseAdapter(){
public void mouseEntered(MouseEvent e, SGNode node) {
mouseTrigger.mouseEntered(e);
}

public void mouseExited(MouseEvent e, SGNode node) {
mouseTrigger.mouseExited(e);
}
});
panel.setScene(node);
add(panel, BorderLayout.CENTER);
}
});
}
}
_______________ JSGPanelTest.java end ____________________

A solution to this problem could be something like:

________________ JSGPanelRepainter.java line 40 ____________
class JSGPanelRepainter {
Set dirtyPanels = new HashSet();

private final FrameJob frameJob;

// private final static JSGPanelRepainter instance =
// new JSGPanelRepainter();
// static JSGPanelRepainter getJSGPanelRepainter() {
// return instance;
// }
//
// private JSGPanelRepainter() {
// frameJob = new FrameDisplay();
// Timeline.addFrameJob(frameJob);
// }
JSGPanelRepainter() {
frameJob = new FrameDisplay();
Timeline.addFrameJob(frameJob);
}
________________ JSGPanel.java line 620 ____________
/*
* Dirty region management below...
*/
private JSGPanelRepainter repainter;
/**
* Notifies this JSGPanel that the scene contained within has been
* made dirty. This is mainly useful for JSGPanels that are embedded
* in an SGComponent so that this JSGPanel's dirty region can be properly
* reported as part of the painting process of that SGComponent.
*/
final void markDirty() {
//JSGPanelRepainter.getJSGPanelRepainter().addDirtyPanel(this);
if (repainter==null){
repainter = new JSGPanelRepainter();
}
repainter.addDirtyPanel(this);
}
________________ JSGPanel.java end____________

I’m looking forward to see your solution to the problem :-)

Kind regards,
Morten

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
idk
Offline
Joined: 2005-01-12
Points: 0

Thank you for the report. I checked in a fix for this bug into the repository (r273)

-Igor