Android Studio: libgdx scene2d: InputMultiplexer not working in release mode. Application crashes

37 views Asked by At

I have put together a framework for a game that also works (several apps have already been created with this framework). Up to Gradle version 7.4.2, both build variants (debug - release) work perfectly. When upgrading to Gradle 8.1.1 only the debug version works. Release crashes as soon as you tap on the display or click on the screen in the emulator. If I comment out the multiplexer in base screen "show()" the multiplexer, the release version works too (see code). Do I have problems with the multiplexer?

Something else I noticed: When I change the build variant from Debug to Release, a dialog opens. I can't post a release here. Then click on select module at the top several times, then the error message will disappear. Could that be the mistake?

Android Studio: libgdx scene2d: InputMultiplexer not working in release mode. Application crashes

enter image description here

enter image description here

public abstract class BaseGame extends Game
{
    public static TextButton.TextButtonStyle textButtonStyle;
    /**
     *  Stores reference to game; used when calling setActiveScreen method.
     */
    private static BaseGame game;

    /**
     *  Called when game is initialized; stores global reference to game object.
     */
    public BaseGame() 
    {        
        game = this;
    }
    
    /**
     *  Called when game is initialized, 
     *  after Gdx.input and other objects have been initialized.
     */
    public void create() 
    {        
       // prepare for multiple classes/stages/actors to receive discrete input
        InputMultiplexer im = new InputMultiplexer();
        Gdx.input.setInputProcessor( im );
    }
    
    /**
     *  Used to switch screens while game is running.
     *  Method is static to simplify usage.
     */
    public static void setActiveScreen(BaseScreen s)
    {
        game.setScreen(s);
    }

    @Override
    public void dispose() {

        //wird nur hier Automatisch aufgerufen!!!!!!!!!!!!!!!
        screen.dispose();

    }
public abstract class BaseScreen implements Screen, InputProcessor
{
    protected Stage mainStage;
    protected Stage uiStage;
    Viewport viewport;

    public BaseScreen()
    {



        mainStage = new Stage(viewport=new ExtendViewport(380,950));
        uiStage = new Stage(viewport=new ExtendViewport(380,950));

        initialize();
    }

    public abstract void initialize();

    public abstract void update(float dt);


    public void render(float dt)
    {

        // act methods
        uiStage.act(dt);
        mainStage.act(dt);

        // clear the screen
        Gdx.gl.glClearColor(255,0,0,1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        
        // draw the graphics
        mainStage.draw();
        uiStage.draw();
        // defined by user
        update(dt);

    }

    // methods required by Screen interface
    public void resize(int width, int height) {
        mainStage.getViewport().update(width, height);
        uiStage.getViewport().update(width, height);
    }

    public void pause()   {  }

    public void resume()  {  }

    public void dispose() {

    }

     /**
     *  Called when this becomes the active screen in a Game.
     *  Set up InputMultiplexer here, in case screen is reactivated at a later time.
     */
    public void show()    
    {
        InputMultiplexer im = (InputMultiplexer)Gdx.input.getInputProcessor();
        im.addProcessor(this);
        im.addProcessor(uiStage);
        im.addProcessor(mainStage);
    }

    /**
     *  Called when this is no longer the active screen in a Game.
     *  Screen class and Stages no longer process input.
     *  Other InputProcessors must be removed manually.
     */
    public void hide()    
    {  
        InputMultiplexer im = (InputMultiplexer)Gdx.input.getInputProcessor();
        im.removeProcessor(this);
        im.removeProcessor(uiStage);
        im.removeProcessor(mainStage);
    }
    
    // methods required by InputProcessor interface
    public boolean keyDown(int keycode)
    {  return false;  }

    public boolean keyUp(int keycode)
    {  return false;  }

    public boolean keyTyped(char c) 
    {  return false;  }

    public boolean mouseMoved(int screenX, int screenY)
    {  return false;  }

    public boolean scrolled(int amount) 
    {  return false;  }

    public boolean touchDown(int screenX, int screenY, int pointer, int button) 
    {  return false;  }

    public boolean touchDragged(int screenX, int screenY, int pointer) 
    {  return false;  }

    public boolean touchUp(int screenX, int screenY, int pointer, int button)
    {  return false;  } 

public class SpaceGame extends BaseGame
{
    public void create() 
    {        
        super.create();
        setActiveScreen( new Start() );
    }
} 

1

There are 1 answers

0
HermannGo On

Thank you very much for the right tip, "Bornander".

Have in the build.gradle (android) the line "minifyEnabled=true" commented out. Now the release works too.