title: How to use SpriteBatch and ShapeRenderer in one screen?
body: <p>I'm using SpriteBatch to draw textures and ShapeRenderer to draw some shape.</p>
  
  <p>Here is my code in an actor</p>
  
  <pre><code>@Override
  public void draw(Batch batch, float parentAlpha) {
      batch.end();
      Gdx.gl.glEnable(GL20.GL_ARRAY_BUFFER_BINDING);
      Gdx.gl.glEnable(GL20.GL_BLEND);
      Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
      shapeRenderer.begin(ShapeType.Filled);
  
      //change color
  
      shapeRenderer.setColor(color);
  
      shapeRenderer.rect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
  
      shapeRenderer.end();
      Gdx.gl.glDisable(GL20.GL_BLEND);
      batch.begin();
  }
  </code></pre>
  
  <p>and call stage.draw() on the screen</p>
  
  <pre><code>@Override
  public void render(float delta) {
      Gdx.gl20.glClearColor(0, 0, 0, 0);
      Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
      Gdx.gl20.glEnable(GL20.GL_TEXTURE_2D);
      stage.act(delta);
      stage.draw();
      //......
  }
  </code></pre>
  
  <p>It's working but unpredictably throw exception:</p>
  
  <pre><code>STACK_TRACE=java.lang.IllegalStateException: SpriteBatch.end must be called before begin.
  at com.badlogic.gdx.graphics.g2d.SpriteBatch.begin(SpriteBatch.java:164)
  at com.badlogic.gdx.scenes.scene2d.Stage.draw(Stage.java:127)
  at c.i.a.a(AbstractCardRoomRenderer.java:3078)
  at c.i.s.a(TLMNCardRoomRenderer.java:1158)
  at c.j.e.render(GameScreen.java:22)
  at com.badlogic.gdx.Game.render(Game.java:46)
  at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:422)
  at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1522)
  at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)
  </code></pre>
  
  <p>EDIT: For more details what I'm doing:</p>
  
  <p>What I want is to draw a shape. Because the stage's batch is drawing so I have to end it for shape drawing. My code still work but sometime, another actor, I think, use stage's batch to draw something else. It make the stage begin its batch. So it conflict between begin and end. </p>
  
  <p>For example, the actor draw method:</p>
  
  <pre><code>batch.end();
  //drawing shapes
  
           batch.begin() (somewhere else) &lt;--- I think this code is call when stage call draw on other actor
  
   //drawing completed
   batch.begin() 
  </code></pre>
  
  <p>EDIT:
  If others' answer not suit you, please consider my workaround I post as an answer below.</p>