Skip to main content

JSGPanelRepainter bug

1 reply [Last post]
Joined: 2004-11-03

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):
_______________ 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));
Clip clip = Clip.create(1000,new TimingTargetAdapter(){
Evaluator colorEvaluator = Evaluators.getLinearInstance(Color.class);
public void timingEvent(float fraction, long totalElapsed) {
node.setFillPaint(colorEvaluator.evaluate(,, fraction));
final MouseTrigger mouseTrigger = new MouseTrigger(clip, MouseTriggerEvent.ENTER);
node.addMouseListener(new SGMouseAdapter(){
public void mouseEntered(MouseEvent e, SGNode node) {

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

A solution to this problem could be something like:

________________ 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();
________________ 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() {
if (repainter==null){
repainter = new JSGPanelRepainter();
________________ end____________

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

Kind regards,

Reply viewing options

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

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