Note that there are some explanatory texts on larger screens.

plurals
  1. POrequestRender doesn't seem to render (opengl-es android)
    text
    copied!<p>I have a gameloop running in a thread, my problem is that the </p> <pre><code>mGLSurfaceView.requestRender(); </code></pre> <p>crashes with a null pointer exception. I have a log tag in my onSurfaceCreated method which proves that the surface is created (at least I think) so that's not the problem.</p> <p>I'm thinking that the problem is that requestRender needs a non-static reference. When I tried calling a non-static reference to another method it crashed on that line instead. So I can only assume that threads aren't too friendly with non-statics. I also can't make a static reference to requestRender (which would be an obvious solution).</p> <p>Here is my game loop thread</p> <pre><code>import android.util.Log; public class GameLoop extends Thread { private MyGLSurfaceView myGLSurfaceView; private final static int maxFPS = 30; private final static int maxFrameSkips = 5; private final static int framePeriod = 1000 / maxFPS; public static boolean running; public final static String TAG = "input"; @Override public void run() { running = LaunchActivity.getRunning(); long beginTime; long timeDiff; int sleepTime; int framesSkipped; sleepTime = 0; while (running) { running = LaunchActivity.getRunning(); Log.d(TAG, "gameRunning"); beginTime = System.currentTimeMillis(); framesSkipped = 0; // notice the static reference here GameLogic.update(); Log.d(TAG, "updated"); // not static here myGLSurfaceView.requestRender(); Log.d(TAG, "rendered"); timeDiff = System.currentTimeMillis() - beginTime; sleepTime = (int)(framePeriod - timeDiff); if (sleepTime &gt; 0) { try{ Thread.sleep(sleepTime); Log.d(TAG, "sleeping" + String.valueOf(sleepTime)); }catch(InterruptedException e){} } while(sleepTime &lt; 0 &amp;&amp; framesSkipped &lt; maxFrameSkips){ GameLogic.update(); sleepTime += framePeriod; framesSkipped++; Log.d(TAG, "Frames Skipped"); } } } } </code></pre> <p>And here is my surface created method (which I though could be part of the problem at a long shot)</p> <pre><code>@Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glShadeModel(GL10.GL_SMOOTH); gl.glClearDepthf(1.0f); gl.glEnable(GL10.GL_DEPTH_TEST); gl.glDepthFunc(GL10.GL_LEQUAL); gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST); Log.d(TAG, "SurfaceCreated"); } </code></pre> <p>Oh and by the way i'm using</p> <pre><code>glOrthof </code></pre> <p>projection </p> <p>StackTrace</p> <pre><code>10-05 20:26:44.694: ERROR/AndroidRuntime(18276): FATAL EXCEPTION: Thread-11 10-05 20:26:44.694: ERROR/AndroidRuntime(18276): java.lang.NullPointerException 10-05 20:26:44.694: ERROR/AndroidRuntime(18276): at basicmelon.games.androidgamething.GameLoop.run(GameLoop.java:33) 10-05 20:26:44.694: ERROR/AndroidRuntime(18276): at java.lang.Thread.run(Thread.java:1096) </code></pre> <p>Log TAG</p> <pre><code>10-05 20:28:23.077: DEBUG/input(18923): GLSurfaceViewed 10-05 20:28:23.116: DEBUG/input(18923): Created 10-05 20:28:23.116: DEBUG/input(18923): Resumed 10-05 20:28:23.124: DEBUG/input(18923): gameRunning 10-05 20:28:23.132: DEBUG/input(18923): Updated 10-05 20:28:23.210: DEBUG/input(18923): Paused </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload