렌더링하지 않는 것, 내 문제는 널 포인터 예외로requestRender 내가 스레드에서 실행 gameloop이 (OpenGL을-ES 안드로이드)
mGLSurfaceView.requestRender();
충돌합니다. 서페이스가 생성되었다는 것을 증명하는 onSurfaceCreated 메서드에 로그 태그가 있습니다 (적어도 생각하면) 문제가되지 않습니다.
문제는 requestRender가 비 정적 참조가 필요하다고 생각합니다. 다른 메서드에 대한 비 정적 참조를 호출하려고 시도했을 때 대신 해당 라인에서 충돌했습니다. 그래서 나는 스레드가 비 정적 (non-statics)과 너무 친절하지 않다고 가정 할 수 있습니다. 또한 requestRender에 대한 정적 참조를 만들 수 없습니다 (이는 명백한 해결책이 될 수 있습니다). 여기
여기 내 게임 루프 스레드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 > 0) {
try{
Thread.sleep(sleepTime);
Log.d(TAG, "sleeping" + String.valueOf(sleepTime));
}catch(InterruptedException e){}
}
while(sleepTime < 0 && framesSkipped < maxFrameSkips){
GameLogic.update();
sleepTime += framePeriod;
framesSkipped++;
Log.d(TAG, "Frames Skipped");
}
}
}
}
입니다 그리고 내 표면 생성 (I 비록 장거리 슛에 문제의 일부가 될 수있는) 방법
@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");
}
아, 그리고에 의해입니다 방법 내가 사용하고
glOrthof
투사
,451,515,스택 트레이스
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)
로그 TAG
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
예외의 스택 추적과 로그 메시지를 보여주는 로그 출력을 포함 할 수 있습니까? –
@ P.T. 물론이지. – Jack
@ P.T. 그냥 SurfaceCreated 로그 태그가 호출되지 않는다는 것을 알았습니다. (내 표면이 제대로 만들어지기 때문에) 그리고 게임 루프 코드에 대해 약간 익숙해졌습니다. (MyGLSurfaceView에 대한 참조에서'= new GLSurfaceView'를 없앴습니다.) – Jack