title: underflow in restore in android 4.3
body: <p>I'm getting a <strong>IllegalStateException: underflow in restore exception,</strong> which is causing my application to crash.
  This started happening after android 4.3 update. On android 3.0 - 4.2.x it works fine.</p>
  
  <p>The exception happens on the second</p>
  
  <pre><code>canvas.restore();
  </code></pre>
  
  <p>Given below is my drawing code</p>
  
  <pre><code>private void doDraw(Canvas canvas) {
          if(mTickerBackGround!=null &amp;&amp; (!mTickerBackGround.isRecycled())){
              canvas.drawBitmap(mTickerBackGround, 0, 0, null);
          }
          if((mBitMapBuffer!=null)){
              canvas.save();
              canvas.translate(mX, 0);
              if(!mBitMapBuffer.isRecycled()){
                  canvas.drawBitmap(mBitMapBuffer, 0, 0, null);
              }
              canvas.restore();
  
              if(bitMapWidth+mX&lt;mCanvasWidth){
                  canvas.translate(bitMapWidth+mX, 0);    
                  if(!mBitMapBuffer.isRecycled()){
                      canvas.drawBitmap(mBitMapBuffer, 0, 0, null);
                  }
                  canvas.restore();                   
              }
  
              if(bitMapWidth+mX&lt;=0){
                  mX = 0;
              }else if(Math.abs(mX)&gt;(bitMapWidth)){                   
                  mX= mCanvasWidth; 
              }
  
              mX-=TickerConstants.SCROLLING_SMOOTHNESS*density;;
          }
          if(mLogo!=null &amp;&amp; (!mLogo.isRecycled())){
              canvas.drawBitmap(mLogo, mCanvasWidth-(60*density), mLogo.getHeight()/6, null);
          }
      }
  </code></pre>
  
  <p>My question is</p>
  
  <ol>
  <li>What is the meaning of this error?</li>
  <li>How do i fix this error?</li>
  </ol>
  
  <p>Stack trace message generated is . Line 165 corresponds to second canvas.restore()</p>
  
  <blockquote>
    <p>08-13 18:13:09.083: E/AndroidRuntime(14139): FATAL EXCEPTION:
    Thread-506 08-13 18:13:09.083: E/AndroidRuntime(14139):
    java.lang.IllegalStateException: Underflow in restore 08-13
    18:13:09.083: E/AndroidRuntime(14139):    at
    android.graphics.Canvas.restore(Native Method) 08-13 18:13:09.083:
    E/AndroidRuntime(14139):  at
    com.my.package.name.ticker.TickerSurfaceView$TickerThread.doDraw(TickerSurfaceView.java:165)
    08-13 18:13:09.083: E/AndroidRuntime(14139):  at
    com.my.package.name.ticker.TickerSurfaceView$TickerThread.run(TickerSurfaceView.java:128)</p>
  </blockquote>