Slick Forums

Discuss the Slick 2D Library
It is currently Sat May 18, 2013 8:38 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Tue Apr 24, 2012 1:44 am 
Offline

Joined: Tue Apr 24, 2012 12:23 am
Posts: 3
Hello Slick Forums,


I'm having an issue with CanvasGameContainer (surprise...). I am embedding it into a LayeredPane, as I wish for some JPanel utilities to be able to pop up on top of the CanvasGameContainer. When starting up my Gui, the CanvasGameContainer does not paint until I click on it for whatever reason. I have dug into the LWJGL layer underneath and I cannot figure out why it is causing that.

Additionally, when I attempt to exit my GUI, my JVM freezes and I have to close it with the terminate button in eclipse or through task manager.

Any ideas at all would be greatly appreciated. I'm at a loss, however I'll keep trying and post updates here as they come.


Thank you!


Top
 Profile  
 
PostPosted: Tue Apr 24, 2012 6:24 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1466
The canvas game container has undergone some changes and bug fixes recently, so I'd recommend pulling the latest code from the dev branch.

I've updated the tests, as well. If you don't want to pull the latest changes, the new test code should (in theory) also work on older versions of Slick, give or take some minor bugs.

The tests work like this:

CanvasContainerTest - shows how to use a canvas game container to achieve a "fixed-size" game; i.e. you can resize the JFrame and it won't resize the actual game. Also, the game will be centred in the JFrame.

CanvasSizeTest - simple use of CanvasGameContainer; resizing our JFrame will resize the game as well.


Regarding your two problems:
- You need to call System.exit when closing the frame. Either manually, or using JFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE). Also, it's good practice to destroy OpenGL before closing, with GameContainer.exit. In the tests you'll also see that I hide the frame before destroying OpenGL; this just looks a bit better than leaving it open as the OpenGL canvas is lost.
- By default, game containers don't update/render if the container (in this case the canvas) is not active/focused. So I've included a requestFocusInWindow method which should solve this. You could, instead, use GameContainer.setAlwaysRender(true) to avoid this issue.


Top
 Profile  
 
PostPosted: Thu Apr 26, 2012 7:12 pm 
Offline

Joined: Tue Apr 24, 2012 12:23 am
Posts: 3
I believe I have been disposing of the canvas properly, here is my exit code:

Code:
private void quitMenuItemActionPerformed(ActionEvent evt) {
      mContainer.setVisible(false);
      mContainer.getContainer().exit();
      mContainer.dispose();
      System.exit(0);
   }


And it still freezes. It may not be a Slick problem, but would you know how to start diagnosing the problem? I guess I'm not familiar enough with Eclipse debugging tools to have a method come to mind. :c


Top
 Profile  
 
PostPosted: Thu Apr 26, 2012 7:28 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1466
Older versions of slick had a bug that didn't properly destroy Display/OpenGL when calling exit(). Have you tried using the latest dev branch code?

And are you sure the System.exit is actually being called? Put in a System.out.println just before it to be sure.

If you really don't want to pull the latest changes, you could use this temporary workaround to destroy OpenGL before calling System.exit:
Code:
      if (Display.isCreated())
            Display.destroy();
      if (AL.isCreated())
            AL.destroy();


Top
 Profile  
 
PostPosted: Fri Apr 27, 2012 1:22 am 
Offline

Joined: Tue Apr 24, 2012 12:23 am
Posts: 3
Thank you so much. That fixed the problem! :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group