Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  BufferStrategy IllegalStateException  (Read 298 times)
0 Members and 2 Guests are viewing this topic.
Offline Spudgun

JGO n00b
*

Posts: 5



« on: 2012-01-14 18:07:41 »

I've moved over to use BufferStrategy from BufferedImage for my first attempt at a game (I'm using Java2D as a learning experience) and the performance boost is pretty noticeable.  I'm constructing the game as an applet for the time being and it's all working fine, but when running it from Netbeans/AppletViewer I get an ugly IllegalStateException showing up in the console when I close down the applet.  Presumably that's because I'm killing it mid-flow.

Is there any particular way I should be handling this?  I could of course put the BufferStrategy code in a try block and handle the exception that way, but I just wanted to check if that was the right thing to do and/or if there is a better way of doing it?
Offline theagentd

JGO Wizard
****

Posts: 1392
Medals: 88



« Reply #1 on: 2012-01-14 18:39:51 »

Well, how are you killing it?

There is no god.
Offline Spudgun

JGO n00b
*

Posts: 5



« Reply #2 on: 2012-01-14 18:58:53 »

Well I presume it's the act of closing down the applet, as in closing the window.  It's only an (un?)educated guess as everything is fine when it's running!

I'm just checking if there is anything else I should be doing.  Below is my game loop code, which is pretty similar to tutorials and other posts on this board.  I've never seen any examples of putting the drawing code in a try block and was wondering if there was a reason for it and if the IllegalStateException is common when exiting.  The exception might not even be an issue since I'm closing it down anyway, but I've only been playing with BufferStrategy for the last week so I'm very green!

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
        while(t == gameloop) {
            threadDelay = GAME_FRAME_DELAY - (System.currentTimeMillis() - lastloop);
            try {
                Thread.sleep(threadDelay);
            } catch (InterruptedException e) {
                //do nothing
           }

            //update game logic
           gameUpdate();

                do{
                    do{
                        Graphics2D g = (Graphics2D)strategy.getDrawGraphics();

                        render(g);

                        g.dispose();
                    }while(strategy.contentsRestored());

                    strategy.show();
                    Toolkit.getDefaultToolkit().sync();
                } while(strategy.contentsLost());
           
            lastloop = System.currentTimeMillis();
        }
    }
Games published by our own members! Go get 'em!
Offline ra4king

JGO Kernel
*****

Posts: 3149
Medals: 196


I'm the King!


« Reply #3 on: 2012-01-14 22:38:07 »

I've never gotten an exception from closing down an applet using BufferStrategy before.

However, this image should give me all the information I need:

Offline theagentd

JGO Wizard
****

Posts: 1392
Medals: 88



« Reply #4 on: 2012-01-14 23:38:29 »

I've never gotten an exception from closing down an applet using BufferStrategy before.

However, this image should give me all the information I need:

If I ever get an office, this is what I'd put up.

There is no god.
Offline ra4king

JGO Kernel
*****

Posts: 3149
Medals: 196


I'm the King!


« Reply #5 on: 2012-01-15 03:02:00 »

I've never gotten an exception from closing down an applet using BufferStrategy before.

However, this image should give me all the information I need:

If I ever get an office, this is what I'd put up.
It's my most favorite picture in the world Smiley

Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.096 seconds with 19 queries.