Greetings.
Okay, using BufferStrategy and rendering nicely to the screen. When a user decides to quit, I can pretty much guarantee that the system will throw an exception upon leaving because of the BufferStrategy. I think it is nulled at some point, and before anyone starts suggesting I debug the code, that’s not the point of this post.
The point is to ask (and hopefully others will benefit from the question) what other developers are doing to exit their game without throwing an exception? I am not sure what should be done when, that’s what I’m examining now, but some guidance would be very appreciated.
Code:
fsf.startRenderThread();
fsf.setDisplayFPS( true );
while( !fsf.bEnd )
{
// Wait
}
fsf.stopRenderThread();
fsf.initFromScreen();
public void startRenderThread()
{
timer.start();
if ( doRender == false )
{
timeLastFrame = timer.getClockTicks();
pauseRender = false;
doRender = true;
renderThread = new Thread( this, "Render Thread" );
renderThread.start();
}
}
public void stopRenderThread()
{
doRender = false;
pauseRender = false;
}
public void run()
{
boolean contentsLost = false;
try
{
while ( doRender )
{
if ( !pauseRender )
{
if ( doRender( null ) )
{
bufferStrategy.show();
}
timer.sleep( renderLoopSpeed );
}
}
}
catch ( Exception x )
{
}
}
public void initFromScreen()
{
if ( !windowed )
{
graphicsDevice.setDisplayMode( oldDisplayMode );
graphicsDevice.setFullScreenWindow( null );
}
}
Thanks.