2

I try to deploy my libgdx game in HTML. In desktop and Android it works well. When I do ./gradlew html:dist, it compile fine and I have a dist folder which is created in html folder. I succeeded to launch the game on a browser: enter image description here

However, when I click on any button which will change the screen, the game crash: enter image description here

The error is :

GwtApplication: exception: (TypeError) : a.g[a.b] is undefined (TypeError) : a.g[a.b] is undefined

and in the console, I have:

Error: java.lang.RuntimeException: com.google.gwt.core.client.JavaScriptException: (TypeError) : a.g[a.b] is undefined

Two questions (1, 2) have the same problem but none of these solved mine.

----- Here is how I change screen ----

When user click on Stats for exemple, my code do that:

button_stats.addListener(new ClickListener(){
        @Override
        public void clicked(InputEvent event, float x, float y){

            stage.addAction(Actions.sequence(Actions.fadeOut(0.2f), Actions.run(new Runnable(){
                @Override
                public void run() {
                    ScreenManager.getInstance().showScreen(ScreenEnum.STATS);
                    }
            })));
        }
    });

Here is my screen manager:

public class ScreenManager {

    // Singleton: unique instance
    private static ScreenManager instance;

    // Reference to game
    private SpeedRun2Game game;

    // Singleton: private constructor
    private ScreenManager() {
        super();
    }

    // Singleton: retrieve instance
    public static ScreenManager getInstance() {
        if (instance == null) {
            instance = new ScreenManager();
        }
        return instance;
    }

    // Initialization with the game class
    public void initialize(SpeedRun2Game game) {
        this.game = game;
    }

    // Show in the game the screen which enum type is received
    public void showScreen(com.gangscred.speedrun2.screens.ScreenEnum screenEnum, Object... params) {

        // Get current screen to dispose it
        Screen currentScreen = game.getScreen();

        // Show new screen
        Screen newScreen = screenEnum.getScreen(game , params);
        game.setScreen(newScreen);

        // Dispose previous screen
        if (currentScreen != null) {
            currentScreen.dispose();
        }
    }
}

and finally my screenEnum:

public enum ScreenEnum {
STATS{
  public Screen getScreen(SpeedRun2Game game, Object... params){
      return new StatsScreen(game);
  }
}

----- EDIT -----

I added style = 'PRETTY' option as suggested to my gwt compiler, and now I have this error:

Error: java.lang.RuntimeException: com.google.gwt.core.client.JavaScriptException: (TypeError) : this$static.uniforms[this$static.currProgram] is undefined

Benjamin Lucidarme
  • 1,648
  • 1
  • 23
  • 39
  • Please don't post the same question twice https://stackoverflow.com/questions/50817992/export-libgdx-project-to-html-did-you-forget-to-inherit-a-required-module/50818703#50818703 – Knarf Jun 13 '18 at 11:27
  • 1
    Did you read this question and the other one??? It's absolutly another problem. Please before downvoting and comment something like that, take 2min to read and try to understand what question means – Benjamin Lucidarme Jun 13 '18 at 11:37
  • We're going to need a little more information to help - can you compile your app with `style=PRETTY`? I'm not sure how your gradle is set up, but when invoking the GWT compiler, that should be an option. Alternatively, enable sourcemaps, or deobfuscate the stack trace, but I think PRETTY will be easier to match to your code. Please note that "TypeError" is just JS's useless way of saying "I don't get it", and so the linked questions really aren't related (esp the `nullMethod` one - `a.g[a.b]` is definitely not `nullMethod`). – Colin Alworth Jun 13 '18 at 13:54
  • @ColinAlworth Thanks for your answer. I updated my question with the new error, but i still don't understand what's wrong.. `Error: java.lang.RuntimeException: com.google.gwt.core.client.JavaScriptException: (TypeError) : this$static.uniforms[this$static.currProgram] is undefined` – Benjamin Lucidarme Jun 13 '18 at 14:29
  • Somewhere in your code, you have `uniforms[currProgram].someMethodOrField` or something like that - getting the rest of the context of that code in both PRETTY JS and in your Java will help to debug this. Since that is null, the someMethodOrField on top breaks in JS with the TypeError. You can configure your browser's dev tools to pause on exceptions so you can see the stack trace, and the values of the variables/fields at that time. – Colin Alworth Jun 13 '18 at 20:15
  • @ColinAlworth Okay thanks, I found the solution. Your advice to put style='PRETTY' was really usefull. I posted an answer – Benjamin Lucidarme Jun 13 '18 at 22:39

1 Answers1

2

For some reason,in HTML you can't use static method in new Runnable. So when you want to change your screen, you need to remove the fadeout:

button_stats.addListener(new ClickListener(){
    @Override
    public void clicked(InputEvent event, float x, float y){
         ScreenManager.getInstance().showScreen(ScreenEnum.STATS);
    }
});

Or you can keep the fadeout but remove your static function and change screen directly:

SpeedRun2Game game;
...
button_stats.addListener(new ClickListener(){
    @Override
    public void clicked(InputEvent event, float x, float y){

        stage.addAction(Actions.sequence(Actions.fadeOut(0.2f), Actions.run(new Runnable(){
            @Override
            public void run() {
                game.setScreen(new StatsScreen(game));
                }
        })));
    }
});
Benjamin Lucidarme
  • 1,648
  • 1
  • 23
  • 39