"Not Responding" + Doesnt show

I've set up a basic copy of TestLoadingGameState, but when I run it, two things happen: first, the window is just black. Second, when I try to close it, it says "Program not responding" or something of the like. Can anyone explain why?



Here is my code, if you need it:


package classes;

import java.util.logging.Level;



import com.jme.app.BaseGame;
import com.jme.input.KeyInput;
import com.jme.input.MouseInput;
import com.jme.input.joystick.JoystickInput;
import com.jme.system.DisplaySystem;
import com.jme.system.JmeException;
import com.jme.util.LoggingSystem;
import com.jmex.game.state.GameState;
import com.jmex.game.state.GameStateManager;
import com.jme.util.Timer;
import com.jmex.game.state.load.LoadingGameState;

public class WhoNeedsWindows extends BaseGame {

   public static BaseGame instance = new WhoNeedsWindows();
   
   
   private Timer timer;
   private float tpf;
   //private InputHandler input;
   
   public static void main(String[] args) {
      //Create the GameStateManager
      GameStateManager.create();
      instance.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG, WhoNeedsWindows.class.getResource("GibiSmall.jpg"));
      instance.start();

   }
   
   public static void exit(){
      instance.finish();
   }
   
   protected void cleanup() {
      LoggingSystem.getLogger().log(Level.INFO, "Cleaning up resources.");
      
      // Performs cleanup on all loaded game states.
      GameStateManager.getInstance().cleanup();
      
        KeyInput.destroyIfInitalized();
        MouseInput.destroyIfInitalized();
        JoystickInput.destroyIfInitalized();

   }

   protected void initGame() {
      display.setTitle("Who Needs Windows? - The Only Game with Homicidal Penguins!");
      

      
[color=Red]      // Create LoadingGameState and enable
      LoadingGameState loading = new LoadingGameState();
      GameStateManager.getInstance().attachChild(loading);
      loading.setActive(true);
      
      // Start our slow loading test
      String status = "Started Loading";
      for (int i = 0; i <= 100; i++) {
         if (i == 100) {
            status = "I'm Finished!";
         } else if (i > 80) {
            status = "Almost There!";
         } else if (i > 70) {
            status = "Loading Something Extremely Useful";
         } else if (i > 50) {
            status = "More Than Half-Way There!";
         } else if (i > 20) {
            status = "Loading Something That You Probably Won't Care About";
         }
         try{
            Thread.sleep(100);
         }catch(Exception e){}
         loading.setProgress((float)i / 100.0f, status);
      }[/color]
   }

   protected void initSystem() {
      try {
         /** Get a DisplaySystem acording to the renderer selected in the startup box. */
         display = DisplaySystem.getDisplaySystem(properties.getRenderer());
         /** Create a window with the startup box's information. */
         display.createWindow(
               properties.getWidth(),
               properties.getHeight(),
               properties.getDepth(),
               properties.getFreq(),
               properties.getFullscreen());
         /** Create a camera specific to the DisplaySystem that works with
          * the display's width and height*/         
      }
      catch (JmeException e) {
         /** If the displaysystem can't be initialized correctly, exit instantly. */
         e.printStackTrace();
         System.exit(1);
      }
      
      /** Get a high resolution timer for FPS updates. */
      timer = Timer.getTimer();
   }

   @Override
   protected void reinit() {
      // TODO Auto-generated method stub

   }

   protected void render(float interpolation) {
      // Clears the previously rendered information.
      display.getRenderer().clearBuffers();
      // Render the current game state.
      GameStateManager.getInstance().render(tpf);

   }

   protected void update(float interpolation) {
      // Recalculate the framerate.
      timer.update();
      tpf = timer.getTimePerFrame();
      
      // Update the current game state.
      GameStateManager.getInstance().update(tpf);

   }



}


Hi,



I'd assume it's because you have a for loop in the init method which gets called before entering the main game loop.  Since not in the game loop your LoadingGameState isn't being updated or rendered.



Mind you I'm new to jME so I could be horribly wrong  :stuck_out_tongue:




  • Chris

man, i'm getting the same problem, but in my case, one second before the game start, a "Loading Succesfull" appears, but not the progress…

i'm trying to solve this… and if you solve first, please let me know, hehehehe  :smiley:



Guilherme

The problem is you're trying to do all of this in a single thread instead of multithreaded.  StandardGame was designed with multithreading in mind.  If you want to do it you'll likely need to wrap your calls to update the loading state in its own thread that gets started separately after the game itself has started.  Or you could do some wacky update progress effort inside your update method, but that would be overly complicated for what you're trying to do.

Thanks a lot, darkfrog!  :smiley: :smiley: I suppose I just didnt fully understand how to multi-thread with GameStates. I do now though!



By the way, GuilhermeFranchi, heres what I changed if you need it:



New Class: LoaderThread


package classes;

public class LoaderThread implements Runnable{
   
   public void run(){
      // Start our slow loading test
      String status = "Started Loading";
      for (int i = 0; i <= 100; i++) {
         if (i == 100) {
            status = "I'm Finished!";
         } else if (i > 80) {
            status = "Almost There!";
         } else if (i > 70) {
            status = "Loading Something Extremely Useful";
         } else if (i > 50) {
            status = "More Than Half-Way There!";
         } else if (i > 20) {
            status = "Loading Something That You Probably Won't Care About";
         }
         try{
            Thread.sleep(100);
         }catch(Exception e){}
         WhoNeedsWindows.getInstance().loading.setProgress((float)i / 100.0f, status);
      }
   }

}



Replaced: (in initGame)

      // Start our slow loading test
      String status = "Started Loading";
      for (int i = 0; i <= 100; i++) {
         if (i == 100) {
            status = "I'm Finished!";
         } else if (i > 80) {
            status = "Almost There!";
         } else if (i > 70) {
            status = "Loading Something Extremely Useful";
         } else if (i > 50) {
            status = "More Than Half-Way There!";
         } else if (i > 20) {
            status = "Loading Something That You Probably Won't Care About";
         }
         try{
            Thread.sleep(100);
         }catch(Exception e){}
         loading.setProgress((float)i / 100.0f, status);
      }



With:

      // Start our slow loading test
      Thread loader = new Thread(new LoaderThread());
      loader.start();



Basically, I just moved the load screen updater to another thread.

                                          -Gibi }:-@