JDK-5018872 : Browser is crashing when resizing Browserwindow and applet is scaling
  • Type: Bug
  • Component: deploy
  • Sub-Component: plugin
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-03-23
  • Updated: 2004-12-01
  • Resolved: 2004-12-01
Related Reports
Relates :  
Relates :  
Description
) ? selectColor : (n.fixed ? fixedColor : nodeColor));
	int w = fm.stringWidth(n.lbl) + 10;
	int h = fm.getHeight() + 4;
	g.fillRect(x - w/2, y - h / 2, w, h);
	g.setColor(Color.black);
	g.drawRect(x - w/2, y - h / 2, w-1, h-1);
	g.drawString(n.lbl, x - (w-10)/2, (y - (h-4)/2) + fm.getAscent());
    }

    public synchronized void update(Graphics g) {
	Dimension d = getSize();
	if ((offscreen == null) || (d.width != offscreensize.width) || (d.height != offscreensize.height)) {
	    offscreen = createImage(d.width, d.height);
	    offscreensize = d;
	    if (offgraphics != null) {
	        offgraphics.dispose();
	    }
	    offgraphics = offscreen.getGraphics();
	    offgraphics.setFont(getFont());
	}

	offgraphics.setColor(getBackground());
	offgraphics.fillRect(0, 0, d.width, d.height);
	for (int i = 0 ; i < nedges ; i++) {
	    Edge e = edges[i];
	    int x1 = (int)nodes[e.from].x;
	    int y1 = (int)nodes[e.from].y;
	    int x2 = (int)nodes[e.to].x;
	    int y2 = (int)nodes[e.to].y;
	    int len = (int)Math.abs(Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)) - e.len);
	    offgraphics.setColor((len < 10) ? arcColor1 : (len < 20 ? arcColor2 : arcColor3)) ;
	    offgraphics.drawLine(x1, y1, x2, y2);
	    if (stress) {
		String lbl = String.valueOf(len);
		offgraphics.setColor(stressColor);
		offgraphics.drawString(lbl, x1 + (x2-x1)/2, y1 + (y2-y1)/2);
		offgraphics.setColor(edgeColor);
	    }
	}

	FontMetrics fm = offgraphics.getFontMetrics();
	for (int i = 0 ; i < nnodes ; i++) {
	    paintNode(offgraphics, nodes[i], fm);
	}
	g.drawImage(offscreen, 0, 0, null);
    }

    //1.1 event handling
    public void mouseClicked(MouseEvent e) {
    }

    public void mousePressed(MouseEvent e) {
        addMouseMotionListener(this);
	double bestdist = Double.MAX_VALUE;
	int x = e.getX();
	int y = e.getY();
	for (int i = 0 ; i < nnodes ; i++) {
	    Node n = nodes[i];
	    double dist = (n.x - x) * (n.x - x) + (n.y - y) * (n.y - y);
	    if (dist < bestdist) {
		pick = n;
		bestdist = dist;
	    }
	}
	pickfixed = pick.fixed;
	pick.fixed = true;
	pick.x = x;
	pick.y = y;
	repaint();
	e.consume();
    }

    public void mouseReleased(MouseEvent e) {
        removeMouseMotionListener(this);
        if (pick != null) {
            pick.x = e.getX();
            pick.y = e.getY();
            pick.fixed = pickfixed;
            pick = null;
        }
	repaint();
	e.consume();
    }

    public void mouseEntered(MouseEvent e) {
    }

    public void mouseExited(MouseEvent e) {
    }

    public void mouseDragged(MouseEvent e) {
	pick.x = e.getX();
	pick.y = e.getY();
	repaint();
	e.consume();
    }

    public void mouseMoved(MouseEvent e) {
    }

    public void start() {
	relaxer = new Thread(this);
	relaxer.start();
    }

    public void stop() {
	relaxer = null;
    }

}


public class Graph extends Applet implements ActionListener, ItemListener {

    GraphPanel panel;
    Panel controlPanel;

    Button scramble = new Button("Scramble");
    Button shake = new Button("Shake");
    Checkbox stress = new Checkbox("Stress");
    Checkbox random = new Checkbox("Random");

    public void init() {
	setLayout(new BorderLayout());

	panel = new GraphPanel(this);
	add("Center", panel);
	controlPanel = new Panel();
	add("South", controlPanel);

	controlPanel.add(scramble); scramble.addActionListener(this);
	controlPanel.add(shake); shake.addActionListener(this);
	controlPanel.add(stress); stress.addItemListener(this);
	controlPanel.add(random); random.addItemListener(this);

	String edges = getParameter("edges");
	for (StringTokenizer t = new StringTokenizer(edges, ",") ; t.hasMoreTokens() ; ) {
	    String str = t.nextToken();
	    int i = str.indexOf('-');
	    if (i > 0) {
		int len = 50;
		int j = str.indexOf('/');
		if (j > 0) {
		    len = Integer.valueOf(str.substring(j+1)).intValue();
		    str = str.substring(0, j);
		}
		panel.addEdge(str.substring(0,i), str.substring(i+1), len);
	    }
	}
	Dimension d = getSize();
	String center = getParameter("center");
	if (center != null){
	    Node n = panel.nodes[panel.findNode(center)];
	    n.x = d.width / 2;
	    n.y = d.height / 2;
	    n.fixed = true;
	}
    }

    public void destroy() {
        remove(panel);
        remove(controlPanel);
    }

    public void start() {
	panel.start();
    }

    public void stop() {
	panel.stop();
    }

    public void actionPerformed(ActionEvent e) {
	Object src = e.getSource();

	if (src == scramble) {
	    play(getCodeBase(), "audio/computer.au");
	    Dimension d = getSize();
	    for (int i = 0 ; i < panel.nnodes ; i++) {
		Node n = panel.nodes[i];
		if (!n.fixed) {
		    n.x = 10 + (d.width-20)*Math.random();
		    n.y = 10 + (d.height-20)*Math.random();
		}
	    }
	    return;
	}

	if (src == shake) {
	    play(getCodeBase(), "audio/gong.au");
	    Dimension d = getSize();
	    for (int i = 0 ; i < panel.nnodes ; i++) {
		Node n = panel.nodes[i];
		if (!n.fixed) {
		    n.x += 80*Math.random() - 40;
		    n.y += 80*Math.random() - 40;
		}
	    }
	}

    }

    public void itemStateChanged(ItemEvent e) {
	Object src = e.getSource();
	boolean on = e.getStateChange() == ItemEvent.SELECTED;
	if (src == stress) panel.stress = on;
	else if (src == random) panel.random = on;
    }

    public String getAppletInfo() {
	return "Title: GraphLayout \nAuthor: <unknown>";
    }

    public String[][] getParameterInfo() {
	String[][] info = {
	    {"edges", "delimited string", "A comma-delimited list of all the edges.  It takes the form of 'C-N1,C-N2,C-N3,C-NX,N1-N2/M12,N2-N3/M23,N3-NX/M3X,...' where C is the name of center node (see 'center' parameter) and NX is a node attached to the center node.  For the edges connecting nodes to eachother (and not to the center node) you may (optionally) specify a length MXY separated from the edge name by a forward slash."},
	    {"center", "string", "The name of the center node."}
	};
	return info;
    }

} 

-------------------- HTML-Page for Test -----
<html>
  <head>
      <title>Graph Layout (example 1)</title>
  </head>
  <body>
    <h1>Graph Layout (example 1)</h1>
      <hr>
      
      <OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" name="GraphApplet" width="100%" height="100%" codebase="http://java.sun.com/products/plugin/1.2.2/jinstall-1_2_2-win.cab#Version=1,2,2,0">
<PARAM name="code" value="Graph.class">
<PARAM name="type" value="application/x-java-applet;version=1.4">
	<param name=edges value="joe-food,joe-dog,joe-tea,joe-cat,joe-table,table-plate/50,plate-food/30,food-mouse/100,food-dog/100,mouse-cat/150,table-cup/30,cup-tea/30,dog-cat/80,cup-spoon/50,plate-fork,dog-flea1,dog-flea2,flea1-flea2/20,plate-knife">
	<param name=center value="joe">

<COMMENT>
<EMBED type="application/x-java-applet;version=1.4" name="GraphApplet" width="100%" height="100%" pluginspage="http://java.sun.com/products/plugin/" code="Graph.class"
edges="joe-food,joe-dog,joe-tea,joe-cat,joe-table,table-plate/50,plate-food/30,food-mouse/100,food-dog/100,mouse-cat/150,table-cup/30,cup-tea/30,dog-cat/80,cup-spoon/50,plate-fork,dog-flea1,dog-flea2,flea1-flea2/20,plate-knife" center="joe">
<NOEMBED>
</COMMENT>
</noembed></embed>
</object>
      <a href="Graph.java">The source</a>.
  </body>
</html>

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Not resizing the window ;)
(Incident Review ID: 244611) 
======================================================================
###@###.### 2004-03-23
Name: gm110360			Date: 03/23/2004


FULL PRODUCT VERSION :
java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP Professional, Version 2002, Service Pack 1, German

EXTRA RELEVANT SYSTEM CONFIGURATION :
Internet Explorer
Version: 6.0.2800.1106.xpsp2.030422-1633
Product ID:55375-OEM-0043151-73936
Updateversion: SP1; Q832894;Q330994

A DESCRIPTION OF THE PROBLEM :
Starting the applet attatched with the html-file attatched and then resizing the Browser-Window over and over again (do this fast). At some time Internet-Explorer is crashing and attatched Exception-file is written.

Allways the error occurs in:

Function=Java_sun_awt_windows_WColor_getDefaultColor+0x2E1D
Library=C:\Programme\Java\j2re1.4.2_03\bin\awt.dll

This problem occurs on a applet of us which we want to start in full-screen-mode. Because of that the applet is defined with a width and height of 100%.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Open html-Page in Internetexplorer
2. Resize Browserwindow very fst

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Browser and applet should resize
ACTUAL -
Browser is crashing after a while

ERROR MESSAGES/STACK TRACES THAT OCCUR :

An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at PC=0x615243F
Function=Java_sun_awt_windows_WColor_getDefaultColor+0x2E1D
Library=C:\Programme\Java\j2re1.4.2_03\bin\awt.dll

Current Java thread:
	at sun.awt.windows.WToolkit.eventLoop(Native Method)
	at sun.awt.windows.WToolkit.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)

Dynamic libraries:
0x00400000 - 0x00419000 	C:\Programme\Internet Explorer\iexplore.exe
0x77F40000 - 0x77FEE000 	C:\WINDOWS\System32\ntdll.dll
0x77E40000 - 0x77F38000 	C:\WINDOWS\system32\kernel32.dll
0x77BE0000 - 0x77C33000 	C:\WINDOWS\system32\msvcrt.dll
0x77D10000 - 0x77D9C000 	C:\WINDOWS\system32\USER32.dll
0x77C40000 - 0x77C80000 	C:\WINDOWS\system32\GDI32.dll
0x77DA0000 - 0x77E3C000 	C:\WINDOWS\system32\ADVAPI32.dll
0x78000000 - 0x78086000 	C:\WINDOWS\system32\RPCRT4.dll
0x70A70000 - 0x70AD5000 	C:\WINDOWS\system32\SHLWAPI.dll
0x71700000 - 0x71849000 	C:\WINDOWS\System32\SHDOCVW.dll
0x78090000 - 0x78174000 	C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.10.0_x-ww_f7fb5805\comctl32.dll
0x773A0000 - 0x77B9C000 	C:\WINDOWS\system32\SHELL32.dll
0x77310000 - 0x7739B000 	C:\WINDOWS\system32\comctl32.dll
0x7CCC0000 - 0x7CDE1000 	C:\WINDOWS\system32\ole32.dll
0x5B0F0000 - 0x5B124000 	C:\WINDOWS\System32\uxtheme.dll
0x71500000 - 0x715FD000 	C:\WINDOWS\System32\BROWSEUI.dll
0x723C0000 - 0x723D3000 	C:\WINDOWS\System32\browselc.dll
0x75EE0000 - 0x75EFF000 	C:\WINDOWS\system32\appHelp.dll
0x76F90000 - 0x77008000 	C:\WINDOWS\System32\CLBCATQ.DLL
0x770F0000 - 0x7717B000 	C:\WINDOWS\system32\OLEAUT32.dll
0x77010000 - 0x770E3000 	C:\WINDOWS\System32\COMRes.dll
0x77BD0000 - 0x77BD7000 	C:\WINDOWS\system32\VERSION.dll
0x63000000 - 0x63097000 	C:\WINDOWS\system32\WININET.dll
0x76260000 - 0x762E9000 	C:\WINDOWS\system32\CRYPT32.dll
0x76240000 - 0x76250000 	C:\WINDOWS\system32\MSASN1.dll
0x76F50000 - 0x76F60000 	C:\WINDOWS\System32\Secur32.dll
0x765C0000 - 0x76610000 	C:\WINDOWS\System32\cscui.dll
0x765A0000 - 0x765BB000 	C:\WINDOWS\System32\CSCDLL.dll
0x76620000 - 0x76708000 	C:\WINDOWS\System32\SETUPAPI.dll
0x10000000 - 0x1000C000 	C:\Programme\Adobe\Acrobat 6.0\Reader\ActiveX\AcroIEHelper.dll
0x00C80000 - 0x00C8D000 	C:\Programme\Xi\NetTransport 2\NTIEHelper.dll
0x73D30000 - 0x73E22000 	C:\WINDOWS\System32\MFC42.DLL
0x61DC0000 - 0x61DCE000 	C:\WINDOWS\System32\MFC42LOC.DLL
0x1A400000 - 0x1A47A000 	C:\WINDOWS\system32\urlmon.dll
0x63580000 - 0x63830000 	C:\WINDOWS\System32\mshtml.dll
0x75E30000 - 0x75ED8000 	C:\WINDOWS\System32\SXS.DLL
0x76110000 - 0x7619E000 	C:\WINDOWS\System32\shdoclc.dll
0x746F0000 - 0x7477F000 	C:\WINDOWS\System32\MLANG.dll
0x01530000 - 0x01731000 	C:\WINDOWS\System32\msi.dll
0x74670000 - 0x74696000 	C:\WINDOWS\System32\msimtf.dll
0x746A0000 - 0x746E4000 	C:\WINDOWS\System32\MSCTF.dll
0x74640000 - 0x74667000 	C:\WINDOWS\System32\MSLS31.DLL
0x76330000 - 0x7634C000 	C:\WINDOWS\System32\IMM32.DLL
0x6FFB0000 - 0x6FFD5000 	C:\WINDOWS\System32\cdfview.dll
0x76AF0000 - 0x76B1D000 	C:\WINDOWS\System32\WINMM.dll
0x72C90000 - 0x72C99000 	C:\WINDOWS\System32\wdmaud.drv
0x72C80000 - 0x72C88000 	C:\WINDOWS\System32\msacm32.drv
0x77BB0000 - 0x77BC4000 	C:\WINDOWS\System32\MSACM32.dll
0x77BA0000 - 0x77BA7000 	C:\WINDOWS\System32\midimap.dll
0x71A30000 - 0x71A39000 	C:\WINDOWS\System32\wsock32.dll
0x71A10000 - 0x71A25000 	C:\WINDOWS\System32\WS2_32.dll
0x71A00000 - 0x71A08000 	C:\WINDOWS\System32\WS2HELP.dll
0x719B0000 - 0x719EC000 	C:\WINDOWS\system32\mswsock.dll
0x76EA0000 - 0x76ED7000 	C:\WINDOWS\System32\RASAPI32.DLL
0x76E50000 - 0x76E61000 	C:\WINDOWS\System32\rasman.dll
0x71BA0000 - 0x71BEE000 	C:\WINDOWS\System32\NETAPI32.dll
0x76E70000 - 0x76E9B000 	C:\WINDOWS\System32\TAPI32.dll
0x76E40000 - 0x76E4D000 	C:\WINDOWS\System32\rtutils.dll
0x719F0000 - 0x719F8000 	C:\WINDOWS\System32\wshtcpip.dll
0x72240000 - 0x72245000 	C:\WINDOWS\System32\sensapi.dll
0x75A10000 - 0x75AB7000 	C:\WINDOWS\system32\USERENV.dll
0x76EE0000 - 0x76F05000 	C:\WINDOWS\System32\DNSAPI.dll
0x76F70000 - 0x76F77000 	C:\WINDOWS\System32\winrnr.dll
0x76F20000 - 0x76F4D000 	C:\WINDOWS\system32\WLDAP32.dll
0x76F80000 - 0x76F85000 	C:\WINDOWS\System32\rasadhlp.dll
0x6B700000 - 0x6B790000 	C:\WINDOWS\System32\jscript.dll
0x74C30000 - 0x74C9F000 	C:\WINDOWS\System32\mshtmled.dll
0x71CC0000 - 0x71CDB000 	C:\WINDOWS\System32\actxprxy.dll
0x6D140000 - 0x6D14B000 	C:\WINDOWS\System32\dispex.dll
0x76BC0000 - 0x76BEE000 	C:\WINDOWS\System32\credui.dll
0x5E490000 - 0x5E49C000 	C:\WINDOWS\System32\pstorec.dll
0x76AD0000 - 0x76AE5000 	C:\WINDOWS\System32\ATL.DLL
0x72D70000 - 0x72E85000 	C:\WINDOWS\System32\msxml3.dll
0x66D10000 - 0x66D1A000 	C:\WINDOWS\System32\imgutil.dll
0x6D440000 - 0x6D450000 	C:\Programme\Java\j2re1.4.2_03\bin\npjpi142_03.dll
0x5F1A0000 - 0x5F1BA000 	C:\WINDOWS\System32\OLEPRO32.DLL
0x6D310000 - 0x6D327000 	C:\Programme\Java\j2re1.4.2_03\bin\jpiexp32.dll
0x6D380000 - 0x6D398000 	C:\Programme\Java\j2re1.4.2_03\bin\jpishare.dll
0x08000000 - 0x08138000 	C:\PROGRA~1\Java\J2RE14~1.2_0\bin\client\jvm.dll
0x03730000 - 0x03737000 	C:\PROGRA~1\Java\J2RE14~1.2_0\bin\hpi.dll
0x03750000 - 0x0375E000 	C:\PROGRA~1\Java\J2RE14~1.2_0\bin\verify.dll
0x03870000 - 0x03889000 	C:\PROGRA~1\Java\J2RE14~1.2_0\bin\java.dll
0x03890000 - 0x0389D000 	C:\PROGRA~1\Java\J2RE14~1.2_0\bin\zip.dll
0x060E0000 - 0x061EF000 	C:\Programme\Java\j2re1.4.2_03\bin\awt.dll
0x72F70000 - 0x72F93000 	C:\WINDOWS\System32\WINSPOOL.DRV
0x06200000 - 0x06250000 	C:\Programme\Java\j2re1.4.2_03\bin\fontmanager.dll
0x736D0000 - 0x73714000 	C:\WINDOWS\System32\ddraw.dll
0x73B30000 - 0x73B36000 	C:\WINDOWS\System32\DCIMAN32.dll
0x738B0000 - 0x73977000 	C:\WINDOWS\System32\D3DIM700.DLL
0x6D2F0000 - 0x6D304000 	C:\Programme\Java\j2re1.4.2_03\bin\jpicom32.dll
0x07F80000 - 0x07F8F000 	C:\Programme\Java\j2re1.4.2_03\bin\net.dll
0x07F90000 - 0x07FB2000 	C:\Programme\Java\j2re1.4.2_03\bin\dcpr.dll
0x76350000 - 0x76396000 	C:\WINDOWS\system32\comdlg32.dll
0x76940000 - 0x76965000 	C:\WINDOWS\System32\ntshrui.dll
0x76930000 - 0x76937000 	C:\WINDOWS\System32\LINKINFO.dll
0x71A80000 - 0x71A91000 	C:\WINDOWS\system32\MPR.dll
0x75F00000 - 0x75F06000 	C:\WINDOWS\System32\drprov.dll
0x71B90000 - 0x71B9D000 	C:\WINDOWS\System32\ntlanman.dll
0x71C50000 - 0x71C66000 	C:\WINDOWS\System32\NETUI0.dll
0x71C10000 - 0x71C4C000 	C:\WINDOWS\System32\NETUI1.dll
0x71C00000 - 0x71C06000 	C:\WINDOWS\System32\NETRAP.dll
0x71B70000 - 0x71B81000 	C:\WINDOWS\System32\SAMLIB.dll
0x75F10000 - 0x75F19000 	C:\WINDOWS\System32\davclnt.dll
0x73CE0000 - 0x73CF2000 	C:\WINDOWS\System32\shgina.dll
0x75910000 - 0x75A03000 	C:\WINDOWS\System32\MSGINA.dll
0x76300000 - 0x7630F000 	C:\WINDOWS\System32\WINSTA.dll
0x01490000 - 0x014C2000 	C:\WINDOWS\System32\ODBC32.dll
0x01510000 - 0x01528000 	C:\WINDOWS\System32\odbcint.dll
0x76C50000 - 0x76C72000 	C:\WINDOWS\system32\imagehlp.dll
0x6DA00000 - 0x6DA7D000 	C:\WINDOWS\system32\DBGHELP.dll
0x76BB0000 - 0x76BBB000 	C:\WINDOWS\System32\PSAPI.DLL

Heap at VM Abort:
Heap
 def new generation   total 960K, used 721K [0x1a480000, 0x1a580000, 0x1ac30000)
  eden space 896K,  78% used [0x1a480000, 0x1a52eef0, 0x1a560000)
  from space 64K,  34% used [0x1a560000, 0x1a565740, 0x1a570000)
  to   space 64K,   0% used [0x1a570000, 0x1a570000, 0x1a580000)
 tenured generation   total 11252K, used 5400K [0x1ac30000, 0x1b72d000, 0x20880000)
   the space 11252K,  47% used [0x1ac30000, 0x1b1762d8, 0x1b176400, 0x1b72d000)
 compacting perm gen  total 7424K, used 7351K [0x20880000, 0x20fc0000, 0x24880000)
   the space 7424K,  99% used [0x20880000, 0x20fade80, 0x20fae000, 0x20fc0000)

Local Time = Tue Mar 23 08:03:46 2004
Elapsed Time = 281
#
# The exception above was detected in native code outside the VM
#
# Java VM: Java HotSpot(TM) Client VM (1.4.2_03-b02 mixed mode)
#


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
Using Applet GraphLayout out of JDK-Demo-Folder:
-------------------- Applet-Sourcecode ----------------------
/*
 * Copyright (c) 2003 Sun Microsystems, Inc. All  Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * -Redistributions of source code must retain the above copyright
 *  notice, this list of conditions and the following disclaimer.
 *
 * -Redistribution in binary form must reproduct the above copyright
 *  notice, this list of conditions and the following disclaimer in
 *  the documentation and/or other materials provided with the distribution.
 *
 * Neither the name of Sun Microsystems, Inc. or the names of contributors
 * may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 *
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
 * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
 * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT
 * BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT
 * OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS
 * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
 * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
 * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
 * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN
 * IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 *
 * You acknowledge that Software is not designed, licensed or intended for
 * use in the design, construction, operation or maintenance of any nuclear
 * facility.
 */

/*
 * @(#)Graph.java	1.13 03/01/23
 */

import java.util.*;
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;


class Node {
    double x;
    double y;

    double dx;
    double dy;

    boolean fixed;

    String lbl;
}


class Edge {
    int from;
    int to;

    double len;
}


class GraphPanel extends Panel
    implements Runnable, MouseListener, MouseMotionListener {
    Graph graph;
    int nnodes;
    Node nodes[] = new Node[100];

    int nedges;
    Edge edges[] = new Edge[200];

    Thread relaxer;
    boolean stress;
    boolean random;

    GraphPanel(Graph graph) {
	this.graph = graph;
	addMouseListener(this);
    }

    int findNode(String lbl) {
	for (int i = 0 ; i < nnodes ; i++) {
	    if (nodes[i].lbl.equals(lbl)) {
		return i;
	    }
	}
	return addNode(lbl);
    }
    int addNode(String lbl) {
	Node n = new Node();
	n.x = 10 + 380*Math.random();
	n.y = 10 + 380*Math.random();
	n.lbl = lbl;
	nodes[nnodes] = n;
	return nnodes++;
    }
    void addEdge(String from, String to, int len) {
	Edge e = new Edge();
	e.from = findNode(from);
	e.to = findNode(to);
	e.len = len;
	edges[nedges++] = e;
    }

    public void run() {
        Thread me = Thread.currentThread();
	while (relaxer == me) {
	    relax();
	    if (random && (Math.random() < 0.03)) {
		Node n = nodes[(int)(Math.random() * nnodes)];
		if (!n.fixed) {
		    n.x += 100*Math.random() - 50;
		    n.y += 100*Math.random() - 50;
		}
		graph.play(graph.getCodeBase(), "audio/drip.au");
	    }
	    try {
		Thread.sleep(100);
	    } catch (InterruptedException e) {
		break;
	    }
	}
    }

    synchronized void relax() {
	for (int i = 0 ; i < nedges ; i++) {
	    Edge e = edges[i];
	    double vx = nodes[e.to].x - nodes[e.from].x;
	    double vy = nodes[e.to].y - nodes[e.from].y;
	    double len = Math.sqrt(vx * vx + vy * vy);
            len = (len == 0) ? .0001 : len;
	    double f = (edges[i].len - len) / (len * 3);
	    double dx = f * vx;
	    double dy = f * vy;

	    nodes[e.to].dx += dx;
	    nodes[e.to].dy += dy;
	    nodes[e.from].dx += -dx;
	    nodes[e.from].dy += -dy;
	}

	for (int i = 0 ; i < nnodes ; i++) {
	    Node n1 = nodes[i];
	    double dx = 0;
	    double dy = 0;

	    for (int j = 0 ; j < nnodes ; j++) {
		if (i == j) {
		    continue;
		}
		Node n2 = nodes[j];
		double vx = n1.x - n2.x;
		double vy = n1.y - n2.y;
		double len = vx * vx + vy * vy;
		if (len == 0) {
		    dx += Math.random();
		    dy += Math.random();
		} else if (len < 100*100) {
		    dx += vx / len;
		    dy += vy / len;
		}
	    }
	    double dlen = dx * dx + dy * dy;
	    if (dlen > 0) {
		dlen = Math.sqrt(dlen) / 2;
		n1.dx += dx / dlen;
		n1.dy += dy / dlen;
	    }
	}

	Dimension d = getSize();
	for (int i = 0 ; i < nnodes ; i++) {
	    Node n = nodes[i];
	    if (!n.fixed) {
		n.x += Math.max(-5, Math.min(5, n.dx));
		n.y += Math.max(-5, Math.min(5, n.dy));
            }
            if (n.x < 0) {
                n.x = 0;
            } else if (n.x > d.width) {
                n.x = d.width;
            }
            if (n.y < 0) {
                n.y = 0;
            } else if (n.y > d.height) {
                n.y = d.height;
            }
	    n.dx /= 2;
	    n.dy /= 2;
	}
	repaint();
    }

    Node pick;
    boolean pickfixed;
    Image offscreen;
    Dimension offscreensize;
    Graphics offgraphics;

    final Color fixedColor = Color.red;
    final Color selectColor = Color.pink;
    final Color edgeColor = Color.black;
    final Color nodeColor = new Color(250, 220, 100);
    final Color stressColor = Color.darkGray;
    final Color arcColor1 = Color.black;
    final Color arcColor2 = Color.pink;
    final Color arcColor3 = Color.red;

    public void paintNode(Graphics g, Node n, FontMetrics fm) {
	int x = (int)n.x;
	int y = (int)n.y;
	g.setColor((n == pick

Comments
EVALUATION Problem is not reproduceable with 1.5.0 B44. It is reproduceable with 1.4.2_03 and 1.4.2_04. When problem occurs, stack trace pointing at: ----- excerpt from stack trace ------- An unexpected exception has been detected in native code outside the VM. Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at PC=0x71B250F Function=Java_sun_awt_windows_WColor_getDefaultColor+0x2E57 Library=C:\Program Files\Java\j2re1.4.2_04\bin\awt.dll Current Java thread: at sun.awt.windows.WToolkit.eventLoop(Native Method) at sun.awt.windows.WToolkit.run(Unknown Source) at java.lang.Thread.run(Unknown Source) -------- end of excerpt --------------------- I will investigate if there is any known fix in 1.5.0 from either deploy or awt that allows problem to disappear in tiger. Meanwhile, since this problem is not reproduceable in 1.5.0 latest, I will tag it as "tiger-na". ###@###.### 2004-03-23
23-03-2004