PaintSurfaceView crash

14 views Asked by At

I am creating a paint application. i use paintSurfaceView and spectrum. The application crashed after uses three color. I use floodfill methods.

Paint method in PaintSurfaceView

    private void paint(int x, int y) {

        if( x < 0 ||  x >= bitmap.getWidth() || y < 0  || y >= bitmap.getHeight())
            return;
        int targetColor = bitmap.getPixel(x, y);
        if (targetColor != Color.BLACK && targetColor != Common.COLOR_SELECTED) {
            FloodFill.floodFill(bitmap, new Point(x, y), targetColor, Common.COLOR_SELECTED);
            if(bitmapList.size() > MAX_BITMAP){
                for(int i=0 ; i<5 ; i++){
                    bitmapList.remove(i);
                }
            }
            invalidate();

        }

    }

Run method in PaintSurfaceView

 public void run() {
Log.d(LOGTAG, "draw thread started");
long frameStartTime;
long frameTime;
if(Build.BRAND.equalsIgnoreCase("google") && Build.MANUFACTURER.equalsIgnoreCase("asus") && Build.MODEL.equalsIgnoreCase("Nexus 7")){
  Log.w(LOGTAG, "sleep 500ms device asus Nexus 7");
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

try {
    while (drawingActive){
        if(holder == null){
            return;
        }
        frameStartTime = System.nanoTime();
        Canvas canvas = holder.lockCanvas();
        if(canvas != null){
            try{
                canvas.drawColor(Color.WHITE);
                drawBitmap(canvas);
            }finally {
                holder.unlockCanvasAndPost(canvas);
            }
        }
        frameTime = (System.nanoTime() - frameStartTime)/ 1000000;
        if(frameTime < MAX_FRAME_TIME){
            try {
                Thread.sleep(MAX_FRAME_TIME - frameStartTime);
            }catch (Exception e ){}
        }
    }
}catch (Exception e){
    Log.w(LOGTAG, "exception while locking/unlocking");
}
Log.d(LOGTAG, "draw thread finished");
    }

I got surface locked when crash

0

There are 0 answers