From: <ma...@us...> - 2009-06-11 21:07:37
|
Revision: 3222 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3222&view=rev Author: matzon Date: 2009-06-11 21:07:34 +0000 (Thu, 11 Jun 2009) Log Message: ----------- print stacktrace if possible on fatal errors, fixed NPE in paint Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2009-06-03 18:29:05 UTC (rev 3221) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2009-06-11 21:07:34 UTC (rev 3222) @@ -48,6 +48,9 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.io.Writer; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.net.SocketPermission; @@ -237,7 +240,7 @@ String[] requiredArgs = {"al_main", "al_logo", "al_progressbar", "al_jars"}; for(int i=0; i<requiredArgs.length; i++) { if(getParameter(requiredArgs[i]) == null) { - fatalErrorOccured("missing required applet parameter: " + requiredArgs[i]); + fatalErrorOccured("missing required applet parameter: " + requiredArgs[i], null); return; } } @@ -261,7 +264,7 @@ //sanity check if(logo == null || progressbar == null) { - fatalErrorOccured("Unable to load logo and progressbar images"); + fatalErrorOccured("Unable to load logo and progressbar images", null); } // check for lzma support @@ -281,6 +284,18 @@ } } + /** + * Generates a stacktrace in the form of a string + * @param exception Exception to make stacktrace of + * @return Stacktrace of exception in the form of a string + */ + private String generateStacktrace(Exception exception) { + Writer result = new StringWriter(); + PrintWriter printWriter = new PrintWriter(result); + exception.printStackTrace(printWriter); + return result.toString(); + } + /* * @see java.applet.Applet#start() */ @@ -397,11 +412,13 @@ } for(int i=0; i<errorMessage.length; i++) { - int messageX = (getWidth() - fm.stringWidth(errorMessage[i])) / 2; - int messageY = (getHeight() - (fm.getHeight() * errorMessage.length)) / 2; - - og.setColor(errorColor); - og.drawString(errorMessage[i], messageX, messageY + i*fm.getHeight()); + if(errorMessage[i] != null) { + int messageX = (getWidth() - fm.stringWidth(errorMessage[i])) / 2; + int messageY = (getHeight() - (fm.getHeight() * errorMessage.length)) / 2; + + og.setColor(errorColor); + og.drawString(errorMessage[i], messageX, messageY + i*fm.getHeight()); + } } } else { og.setColor(fgColor); @@ -517,11 +534,11 @@ } else if (osName.startsWith("Solaris") || osName.startsWith("SunOS")) { nativeJar = getParameter("al_solaris"); } else { - fatalErrorOccured("OS (" + osName + ") not supported"); + fatalErrorOccured("OS (" + osName + ") not supported", null); } if (nativeJar == null) { - fatalErrorOccured("no lwjgl natives files found"); + fatalErrorOccured("no lwjgl natives files found", null); } else { nativeJar = trimExtensionByCapabilities(nativeJar); urlList[jarCount - 1] = new URL(path, nativeJar); @@ -626,10 +643,10 @@ state = STATE_DONE; } catch (AccessControlException ace) { - fatalErrorOccured(ace.getMessage()); + fatalErrorOccured(ace.getMessage(), ace); certificateRefused = true; } catch (Exception e) { - fatalErrorOccured(e.getMessage()); + fatalErrorOccured(e.getMessage(), e); } finally { loaderThread = null; } @@ -1172,10 +1189,13 @@ * * @param error Error message to print */ - protected void fatalErrorOccured(String error) { + protected void fatalErrorOccured(String error, Exception e) { fatalError = true; fatalErrorDescription = "Fatal error occured (" + state + "): " + error; System.out.println(fatalErrorDescription); + if(e != null) { + System.out.println(generateStacktrace(e)); + } repaint(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |