我收到了IllegalStateException:还原异常中的下溢,这导致我的应用程序崩溃.这在Android 4.3更新后开始发生.在Android 3.0 - 4.2.x它工作正常.
例外情况发生在第二个
canvas.restore();
Run Code Online (Sandbox Code Playgroud)
以下是我的绘图代码
private void doDraw(Canvas canvas) {
if(mTickerBackGround!=null && (!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<mCanvasWidth){
canvas.translate(bitMapWidth+mX, 0);
if(!mBitMapBuffer.isRecycled()){
canvas.drawBitmap(mBitMapBuffer, 0, 0, null);
}
canvas.restore();
}
if(bitMapWidth+mX<=0){
mX = 0;
}else if(Math.abs(mX)>(bitMapWidth)){
mX= mCanvasWidth;
}
mX-=TickerConstants.SCROLLING_SMOOTHNESS*density;;
}
if(mLogo!=null && (!mLogo.isRecycled())){
canvas.drawBitmap(mLogo, mCanvasWidth-(60*density), mLogo.getHeight()/6, null);
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是
生成的堆栈跟踪消息是.第165行对应第二个canvas.restore()
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:恢复08-13下溢18:13:09.083:E/AndroidRuntime(14139):在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)
Rom*_*Guy 14
错误发生在代码的这一部分:
if(bitMapWidth+mX<mCanvasWidth){
canvas.translate(bitMapWidth+mX, 0);
if(!mBitMapBuffer.isRecycled()){
canvas.drawBitmap(mBitMapBuffer, 0, 0, null);
}
canvas.restore();
}
Run Code Online (Sandbox Code Playgroud)
你restore()没有save()先打电话就打电话.您甚至不需要调用它们translate(),您只需将x和y坐标传递给drawBitmap()调用即可.
| 归档时间: |
|
| 查看次数: |
5921 次 |
| 最近记录: |