Skip to main content

[multilib~subversion:57] Added a few null checks, simplelibrary.game.GameHelper supports operating

  • From:
  • To:
  • Subject: [multilib~subversion:57] Added a few null checks, simplelibrary.game.GameHelper supports operating
  • Date: Wed, 16 Apr 2014 15:57:43 +0000

Project:    multilib
Repository: subversion
Revision:   57
Author:     superinventor
Date:       2014-04-16 15:57:42 UTC
Link:       

Log Message:
------------
Added a few null checks, simplelibrary.game.GameHelper supports operating 
within a pre-existing frame now


Revisions:
----------
57


Modified Paths:
---------------
simplelibrary/Sys.java
simplelibrary/window/WindowHelper.java
simplelibrary/game/GameHelper.java


Diffs:
------
Index: simplelibrary/window/WindowHelper.java
===================================================================
--- simplelibrary/window/WindowHelper.java      (revision 56)
+++ simplelibrary/window/WindowHelper.java      (revision 57)
@@ -1,6 +1,5 @@
 package simplelibrary.window;
 import java.awt.Dimension;
-import java.awt.Frame;
 import java.awt.GraphicsDevice;
 import java.awt.GraphicsEnvironment;
 import java.awt.Insets;
Index: simplelibrary/game/GameHelper.java
===================================================================
--- simplelibrary/game/GameHelper.java  (revision 56)
+++ simplelibrary/game/GameHelper.java  (revision 57)
@@ -43,11 +43,12 @@
     private Object tickObject;
     private Object renderObject;
     public JFrame frame;
-    private Canvas canvas;
+    public Canvas canvas;
     private int mode = MODE_2D;
     private int millisPerTick = 50;
     public float guiScale = 1;
     private float lastGuiScale;
+    private boolean self;
     //</editor-fold>
     public void setMaximumFramerate(int maxFramerate){
         framerateCap = maxFramerate;
@@ -119,11 +120,14 @@
                     Controllers.destroy();
                 }
             });
-            frame = WindowHelper.createFrameWithoutAppearance(windowTitle, 
width, height, null);
-            frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
-            canvas = new Canvas();
-            frame.add(canvas);
-            frame.setVisible(true);
+            if(canvas==null||!canvas.isVisible()){
+                frame = 
WindowHelper.createFrameWithoutAppearance(windowTitle, width, height, null);
+                frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
+                canvas = new Canvas();
+                frame.add(canvas);
+                frame.setVisible(true);
+                self = true;
+            }
             canvas.requestFocus();
             Display.setParent(canvas);
             if(background==null){
@@ -177,6 +181,8 @@
             Sys.error(ErrorLevel.severe, "Bug in SimpleLibrary- Illegal 
method managed to get in!", ex, ErrorCategory.bug);
         }catch(InvocationTargetException ex){
             Sys.error(ErrorLevel.severe, "Error initializing!", 
ex.getCause(), ErrorCategory.uncaught);
+        }catch(NullPointerException ex){
+            Sys.error(ErrorLevel.severe, "Init method is not static and init 
object is null!", ex, ErrorCategory.bug);
         }
         getDelta();
         if(tickMethod==null&&renderMethod==null){
@@ -201,8 +207,10 @@
         tick(true);
         Display.destroy();
         Controllers.destroy();
-        frame.setVisible(false);
-        frame.dispose();
+        if(self){
+            frame.setVisible(false);
+            frame.dispose();
+        }
     }
     public int getDelta(){
         long newTime = getTime();
@@ -224,6 +232,8 @@
             Sys.error(ErrorLevel.severe, "Bug in SimpleLibrary- Illegal 
method managed to get in!", ex, ErrorCategory.bug);
         }catch(InvocationTargetException ex){
             Sys.error(ErrorLevel.severe, "Error ticking!", ex.getCause(), 
ErrorCategory.uncaught);
+        }catch(NullPointerException ex){
+            Sys.error(ErrorLevel.severe, "Tick method is not static and tick 
object is null!", ex, ErrorCategory.bug);
         }
     }
     public void render() throws LWJGLException{
@@ -264,6 +274,8 @@
             Sys.error(ErrorLevel.severe, "Bug in SimpleLibrary- Illegal 
method managed to get in!", ex, ErrorCategory.bug);
         }catch(InvocationTargetException ex){
             Sys.error(ErrorLevel.severe, "Error rendering!", ex.getCause(), 
ErrorCategory.uncaught);
+        }catch(NullPointerException ex){
+            Sys.error(ErrorLevel.severe, "Render method is not static and 
render object is null!", ex, ErrorCategory.bug);
         }
         Display.update();
     }
Index: simplelibrary/Sys.java
===================================================================
--- simplelibrary/Sys.java      (revision 56)
+++ simplelibrary/Sys.java      (revision 57)
@@ -330,8 +330,10 @@
         params.addAll(Arrays.asList(vmArgs));
         params.add("-classpath");
         String filepath = 
mainClass.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
-        for(String str : additionalFiles){
-            filepath+=";"+str;
+        if(additionalFiles!=null){
+            for(String str : additionalFiles){
+                filepath+=";"+str;
+            }
         }
         params.add(filepath);
         params.add(mainClass.getName());





[multilib~subversion:57] Added a few null checks, simplelibrary.game.GameHelper supports operating

superinventor 04/16/2014
 
 
Close
loading
Please Confirm
Close