Android Fatal Signal 11

前端 未结 10 1207
小鲜肉
小鲜肉 2020-12-14 05:25

In the app I\'m developing on Android, I keep getting a Fatal Signal 11 error.

I think it\'s something to do with the way that I\'m accessing the memory but I can\'t

10条回答
  •  时光说笑
    2020-12-14 05:50

    Same thing happened to me during game development using LibGDX framework for Android, and here's why:

    I have 2 screens - GameScreen and BattleScreen. GameScreen is where I move my character on the map. When I have collision with enemy sprite I instantly use game.setScreen(new BattleScreen(this)) and change current screen to BattleScreen. Here's where the Fatal Signal 11 used to happen. At first I thought it had something to do with loading assets, because my asset manager instance was static. I was trying multiple ways of loading them but nothing worked. It turned out I was changing the screen in the wrong place. For my GameScreen I had WorldController and WorldRenderer instance. I was using worldController.update() and worldRenderer.render() inside GameScreen's render(float deltaTime) method. Inside worldController.update() I was checking for collisions and changing screen as soon as I found one with the enemy. It was not good for Android, maybe because it happened between update and render, or it took some time, while update was still running and it lead to conflicts - I don't know. But here is how I fixed it:

    1. I added a boolean flag (false by default) inside WorldController and everytime a collision with enemy happened I was setting it to true
    2. In GameScreen's render() I was checking this flag - if it was true I would change the screen to BattleScreen, otherwise I would update and render GameScreen

    Now it works perfectly everytime, no FATAL SIGNAL ERROR 11 whatsoever

    Here's my GameScreen's render() method:

    @Override
    public void render(float deltaTime) {
    
        if(worldController.isCollisionWithEnemy()) {
    
            game.setScreen(game.battleScreen);
    
        } else {
    
            if(!paused) {
                worldController.update(deltaTime);
            }
    
            Gdx.gl.glClearColor(57.0f / 255.0f, 181.0f / 225.0f, 115.0f / 255.0f, 1.0f);
            Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    
            worldRenderer.render();
        }
    
    }
    

提交回复
热议问题