Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 28 Jan 2012
Offline Last Active May 10 2012 08:13 PM

Topics I've Started

Problem with very simple game loop thread

02 May 2012 - 11:41 AM

Hello guys,

I'm learning android game development with Opengl ES and trying to implement a very simple game loop using a separated thread, that is basically just an infinite loop. When I try running the application on the emulator, it enters the infinite loop and doesn't do anything else.. the rendering thread does nothing..

I'm new to programming with threads but, even if the game loop thread is stuck in an infinite loop, isn't the render thread suppose to draw things on screen?

Here is the code of my surfaceview and game thread class (the render class is the triangle drawing example and works fine when I don't start the game thread..)

public class MainThread extends Thread {

private boolean running;
public void setRunning(boolean running) {
  this.running = running;
public void run() {
  while (running) {

class GameSurfaceView extends GLSurfaceView {
	private GameRenderer mRenderer;
	private MainThread mThread;
	public GameSurfaceView(Context context){
		// Create an OpenGL ES 2.0 context.
		// set the mRenderer member
		mRenderer = new GameRenderer();
		mThread = new MainThread ();
		// Render the view only when there is a change
	public void surfaceCreated(SurfaceHolder holder) {
	 // TODO Auto-generated method stub

	public void surfaceDestroyed(SurfaceHolder holder) {
	 boolean retry = true;
	 while (retry) {
	  try {
   } catch (InterruptedException e) {
	// TODO Auto-generated catch block
   retry = false;

This is a very basic example, the game loop is not supposed to do anything, I'm just trying to learn how to make it run while the rendering thread draws the triangle.