Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Problem with very simple game loop thread


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 parnparn   Members   -  Reputation: 100

Like
0Likes
Like

Posted 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;
}
@Override
public void run() {
  while (running) {
  
  }
}
}

class GameSurfaceView extends GLSurfaceView {
	private GameRenderer mRenderer;
	private MainThread mThread;
	
	public GameSurfaceView(Context context){
		super(context);
		// Create an OpenGL ES 2.0 context.
		setEGLContextClientVersion(2);
		  
		// set the mRenderer member
		mRenderer = new GameRenderer();
		setRenderer(mRenderer);
		mThread = new MainThread ();
		// Render the view only when there is a change
		setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
	}
  
	@Override
	public void surfaceCreated(SurfaceHolder holder) {
	 // TODO Auto-generated method stub
	 super.surfaceCreated(holder);
	  
		mThread.setRunning(true);
		mThread.run();
	}
  

	public void surfaceDestroyed(SurfaceHolder holder) {
	 boolean retry = true;
	 while (retry) {
	  try {
	mThread.join();
   } catch (InterruptedException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
   }
   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.

Thanks!

Sponsor:

#2 JoJoSim1   Members   -  Reputation: 173

Like
0Likes
Like

Posted 03 May 2012 - 03:07 AM

I never did any Android stuff. Did you check which lines of code get executed. Insert print/log commands. I'm not sure but shouldn't mThread.run() be mThread.start() ?

#3 Vorel512   Members   -  Reputation: 130

Like
0Likes
Like

Posted 04 May 2012 - 12:00 AM

I suppose, that you are not created any threads. It looks like, that the execution stuck between the mThread class.

#4 Ruben Moreno   Members   -  Reputation: 436

Like
0Likes
Like

Posted 06 June 2012 - 10:20 AM

I never did any Android stuff. Did you check which lines of code get executed. Insert print/log commands. I'm not sure but shouldn't mThread.run() be mThread.start() ?


He nailed it. The run() call simply executes the implementation inline. You have to call start() to launch the run() implementation on its own thread.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS