5

I have a splash screen and a menu screen class that loads all my texture atlases and skins for the menu and processes lots of stuff. If I put the constructor for the menu screen in the SplashScreen constructor or in the create() method of my main game class (MyGame class) then it would pass a lot of time with no splash screen render image on the phone while the whole stuff loads so I have delayed the loading of the menu class to the second frame render (gets called in the SplashScreen render method in the second frame); I simply check if I passed the first frame then I call a method on the main game class that loads the menus.

It all works fine , as expected , but only if the SplashScreen load process is not interrupted. If I get a call or I simple press the HOME button of the mobile and then I re-enter the game by clicking the icon on the home screen I get an AndroidGraphics error : "waiting for pause synchronization took too long: assuming dead lock and killing"; this is just after I can see the splash screen on the screen for about a second;

I tried to dispose the MyGame in the hide() and pause() methods of both the main game class and the splash screen class so it's terminated if I press the HOME button but they never get called.

How can I fix this? It would be annoying to get a call while loading the game and after you finish the call and try to re-enter the game it crashes.

public class MyGame extends Game{
    ...
    public MainMenu menu;
    ...
    @Override
    public void create(){ 
        this.screen_type == SCREEN_TYPE.SPLASH;
        splashScreen = new SplashScreen();
        setScreen(splashScreen);
    }
    ...
    @Override 
    public void pause(){
        //never gets called if I press the HOME button in middle of splash screen
        if(this.screen_type == SCREEN_TYPE.SPLASH)
        {
            this.dispose();
        }
    }
    ... 
    public void LoadMenuTimeConsumingConstructor(){
        //load all menus and process data
        main_menu = new MainMenu();
        loaded_menu = true;
    }
}

public class SplashScreen implements InputProcessor, Screen{

    public MyGame main_game;
    ...
    public SplashScreen(MyGame game){
        this.main_game = game;
    }

    @Override
    public void pause(){
        //never gets called if I press the HOME button in middle of splash screen
        if(main_game.screen_type == SCREEN_TYPE.SPLASH)
        {
            main_game.dispose();
        }
    }

    @Override 
    public void hide(){
        //never gets called if I press the HOME button in middle of splash screen
        if(main_game.screen_type == SCREEN_TYPE.SPLASH)
        {
            main_game.dispose();
        }
    }

    @Override 
    public void render(delta float){
        ...

        //wait 1.5 sec
        if(TimeUtils.millis() - startTime > 1500){
        {
            if(main_game.loaded_menu = true){
                main_game.setScreen(main_game.main_menu);
            }

        } 

        ...

        if(is_this_second_frame){  // we start loading menus in the second frame so we already have the splash onscreen
            main_game.LoadMenuTimeConsumingConstructor();
        }

        ...
    }
}
gogonapel
  • 788
  • 6
  • 17
  • Just to make sure : the waiting time of the splashscreen is not artificial, right? – Docteur May 08 '15 at 08:32
  • Hi! Yes I have a delay of 1500 ms. Only after that I can change the screen if the menus are loaded. I've updated the code above : `if(TimeUtils.millis() - startTime > 1500){` . Not good ? – gogonapel May 08 '15 at 08:38
  • 2
    Hi! While I sadly cannot help on your bug, I do not recommend using a "fake" splashscreen - it is unnecessary, long, and while it does look awesome the first time, it gets boring. There are great ressources on how to make a real one (that disappears when the program is loaded) on the Internet - I can link you some tonight if you're still around -, and doing a real one **may** fix your problem. :-) – Docteur May 08 '15 at 08:41
  • 1
    @Docteur I personally when I made games, what I did was that I made a splash screen that appears for about 2 seconds, but if you tapped it then it ended the splash screen immediately and went to the next screen :D – EpicPandaForce May 08 '15 at 14:46

1 Answers1

2

I do not understand your question very well, but if you are not using AssetManger Class, I think this read can help, I hope so.

If this response is not valid or not useful to you, tell me, and delete

wiki LibGDX https://github.com/libgdx/libgdx/wiki/Managing-your-assets

video on YouTUBE https://www.youtube.com/watch?v=JXThbQir2gU

other example in GitHub https://github.com/Matsemann/libgdx-loading-screen

NEW look this:

Proper way to dispose screens in Libgdx

What's the right place to dispose a libgdx Screen

It can help you decide if you need to call dipose, and how, I hope it will help.

Community
  • 1
  • 1
Angel Angel
  • 19,670
  • 29
  • 79
  • 105
  • Hi ! No need to delete but I already use the AssetManager in my game. My problem is that if the game is in splash screen mode (and loading stuff) and I hit the HOME button then when I re-enter the game by clicking the game icon the system tries to recover the "paused instance" but fails ; i get a game crash ; so I have to click (touch) the icon again again . – gogonapel May 08 '15 at 17:41