Fatal signal 11 (SIGSEGV), code 1, fault addr 0xb8891d68 in tid 15949 (FinalizerDaemon)

自定义了一个画板
底层libc报空指针,求教定位或解决办法
在线等

01-16 10:56:11.764 15941-15941/com.cs.sls.smarterlecturestudents E/SketchView: *2* drawBitmap: ---->drawBitmap tempBitmap after
01-16 10:56:11.852 304-304/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
01-16 10:56:11.852 304-304/? A/DEBUG: Build fingerprint: 'Lenovo/YT3-X50F/YT3-X50F:6.0.1/MMB29M/YT3-X50F_USR_S113_170323_Q1241_PRC:user/release-keys'
01-16 10:56:11.852 304-304/? A/DEBUG: Revision: '0'
01-16 10:56:11.852 304-304/? A/DEBUG: ABI: 'arm'
01-16 10:56:11.852 304-304/? A/DEBUG: pid: 15941, tid: 15949, name: FinalizerDaemon  >>> com.cs.sls.smarterlecturestudents <<<
01-16 10:56:11.852 304-304/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xb8891d68
01-16 10:56:11.889 304-304/? A/DEBUG:     r0 b74360c8  r1 b418b58c  r2 b8891d68  r3 ffffffff
01-16 10:56:11.889 304-304/? A/DEBUG:     r4 b8891d68  r5 6f5e8b24  r6 13051860  r7 b8891d68
01-16 10:56:11.890 304-304/? A/DEBUG:     r8 ffffffff  r9 b73ee2d0  sl 12fb8400  fp 13051860
01-16 10:56:11.890 304-304/? A/DEBUG:     ip b6ede9d1  sp b418b578  lr 720e24c7  pc b6ede9d4  cpsr 60070030
01-16 10:56:11.892 304-304/? A/DEBUG: backtrace:
01-16 10:56:11.893 304-304/? A/DEBUG:     #00 pc 000969d4  /system/lib/libandroid_runtime.so
01-16 10:56:11.893 304-304/? A/DEBUG:     #01 pc 021984c5  /system/framework/arm/boot.oat (offset 0x1eff000)
01-16 10:56:12.791 816-16229/? W/ActivityManager:   Force finishing activity com.cs.sls.smarterlecturestudents/.ui.activity.WhiteBoardActivity

核心onDraw方法如下:

private Bitmap tempBitmap;//临时绘制的bitmap
private Canvas tempCanvas;
private Bitmap tempHoldBitmap;//保存已固化的笔画bitmap
private Canvas tempHoldCanvas;

public void drawRecord(Canvas canvas) {
    //同步绘制
    if (curSketchData != null) {
        //新建一个临时画布,以便橡皮擦生效
        Log.e(TAG, "drawRecord: ---->createBitmap tempBitmap");
        if (tempBitmap == null) {
            tempBitmap = Bitmap.createBitmap(getWidth() / drawDensity, getHeight() / drawDensity, Bitmap.Config.ARGB_4444);
            tempCanvas = new Canvas(tempBitmap);
        }

        //新建一个临时画布,以便保存过多的画笔
        Log.e(TAG, "drawRecord: ---->createBitmap tempHoldBitmap");
        if (tempHoldBitmap == null) {
            tempHoldBitmap = Bitmap.createBitmap(getWidth() / drawDensity, getHeight() / drawDensity, Bitmap.Config.ARGB_4444);
            tempHoldCanvas = new Canvas(tempHoldBitmap);
        }
        //把十个操作以前的笔画全都画进固化层
        while (curSketchData.strokeRecordList.size() > 10) {
            StrokeRecord record = curSketchData.strokeRecordList.get(0);
            strokePaint.setColor(record.color);
            strokePaint.setStrokeWidth(record.strokeWidth);
            Paint paint = new Paint(strokePaint);

            switch (record.type){
                case STROKE_TYPE_ERASER:
                    strokePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));//关键代码

                    Path eraserPath = new Path();
                    strokePaint.setColor(Color.WHITE);
                    strokePaint.setStrokeWidth(eraserSize);


                    paint = new Paint(strokePaint);
                    eraserPath.moveTo(record.downX, record.downY);
                    //历史路径
                    for (StrokeDrawEarserEntity listPathHi : record.listPathHis) {
                        eraserPath.quadTo(listPathHi.preX, listPathHi.preY, (listPathHi.curX + listPathHi.preX) / 2, (listPathHi.curY + listPathHi.preY) / 2);
                    }
                    tempHoldCanvas.drawPath(eraserPath,paint);
                    Log.e(TAG, "drawRecord: ---->tempHoldCanvas eraserPath");
                    break;
                case STROKE_TYPE_DRAW:
                    Path drawPath = new Path();
                    drawPath.moveTo(record.downX, record.downY);

                    for (StrokeDrawEarserEntity listPathHi : record.listPathHis) {
                        drawPath.quadTo(listPathHi.preX, listPathHi.preY, (listPathHi.curX + listPathHi.preX) / 2, (listPathHi.curY + listPathHi.preY) / 2);
                    }
                    tempHoldCanvas.drawPath(drawPath, paint);
                    Log.e(TAG, "drawRecord: ---->tempHoldCanvas drawPath");
                    break;
                case STROKE_TYPE_LINE:
                    Path linePath = new Path();
                    linePath.moveTo(record.downX, record.downY);
                    linePath.lineTo(record.upX, record.upY);
                    tempHoldCanvas.drawPath(linePath, paint);
                    Log.e(TAG, "drawRecord: ---->tempHoldCanvas linePath");
                    break;
                case STROKE_TYPE_CIRCLE:
                    tempHoldCanvas.drawOval(record.rect, paint);
                    Log.e(TAG, "drawRecord: ---->tempHoldCanvas drawOval");
                    break;
                case STROKE_TYPE_RECTANGLE:
                    tempHoldCanvas.drawRect(record.rect, paint);
                    Log.e(TAG, "drawRecord: ---->tempHoldCanvas drawRect");
                    break;
                case STROKE_TYPE_TEXT:
                    if (record.text != null) {
                        TextPaint tp = new TextPaint();
                        tp.setTextSize(record.textSize);
                        tp.setColor(record.color);
                        StaticLayout layout = new StaticLayout(record.text, tp, record.textWidth, Layout.Alignment.ALIGN_NORMAL, 1.0F, 0.0F, true);
                        tempCanvas.translate(record.textOffX, record.textOffY);
                        layout.draw(tempCanvas);
                        tempCanvas.translate(-record.textOffX, -record.textOffY);
                    }
                    Log.e(TAG, "drawRecord: ---->tempHoldCanvas STROKE_TYPE_TEXT");
                    break;

            }

            curSketchData.strokeRecordList.remove(0);
        }
        clearCanvas(tempCanvas);//清空画布
        tempCanvas.drawColor(Color.TRANSPARENT);
        Log.e(TAG, "drawBitmap: ---->drawBitmap tempHoldBitmap before");
        tempCanvas.drawBitmap(tempHoldBitmap, new Rect(0, 0, tempHoldBitmap.getWidth(), tempHoldBitmap.getHeight()), new Rect(0, 0, tempCanvas.getWidth(), tempCanvas.getHeight()), null);
        Log.e(TAG, "drawBitmap: ---->drawBitmap tempHoldBitmap after");
        for (StrokeRecord record : curSketchData.strokeRecordList) {
            strokePaint.setXfermode(null);//关键代码

            strokePaint.setColor(record.color);
            strokePaint.setStrokeWidth(record.strokeWidth);
            Paint paint = new Paint(strokePaint);

            switch (record.type){
                case STROKE_TYPE_ERASER:
                    strokePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));//关键代码

                    Path eraserPath = new Path();
                    strokePaint.setColor(Color.WHITE);
                    strokePaint.setStrokeWidth(eraserSize);


                    paint = new Paint(strokePaint);
                    eraserPath.moveTo(record.downX, record.downY);

                    //历史路径
                    for (StrokeDrawEarserEntity listPathHi : record.listPathHis) {
                        eraserPath.quadTo(listPathHi.preX, listPathHi.preY, (listPathHi.curX + listPathHi.preX) / 2, (listPathHi.curY + listPathHi.preY) / 2);
                    }


                    tempHoldCanvas.drawPath(eraserPath,paint);
                    tempCanvas.drawPath(eraserPath, paint);
                    Log.e(TAG, "*2* drawPath: ---->drawPath eraserPath");
                    break;
                case STROKE_TYPE_DRAW:
                    Path drawPath = new Path();
                    drawPath.moveTo(record.downX, record.downY);

                    for (StrokeDrawEarserEntity listPathHi : record.listPathHis) {
                        drawPath.quadTo(listPathHi.preX, listPathHi.preY, (listPathHi.curX + listPathHi.preX) / 2, (listPathHi.curY + listPathHi.preY) / 2);
                    }
                    tempCanvas.drawPath(drawPath, paint);
                    Log.e(TAG, "*2* drawPath: ---->drawPath drawPath");

                    break;
                case STROKE_TYPE_LINE:
                    Path linePath = new Path();
                    linePath.moveTo(record.downX, record.downY);
                    linePath.lineTo(record.upX, record.upY);
                    tempCanvas.drawPath(linePath, paint);
                    Log.e(TAG, "*2* drawPath: ---->drawPath linePath");
                    break;
                case STROKE_TYPE_CIRCLE:
                    tempCanvas.drawOval(record.rect, paint);
                    Log.e(TAG, "*2* drawPath: ---->drawPath STROKE_TYPE_CIRCLE");
                    break;
                case STROKE_TYPE_RECTANGLE:
                    tempCanvas.drawRect(record.rect, paint);
                    Log.e(TAG, "*2* drawPath: ---->drawPath STROKE_TYPE_RECTANGLE");
                    break;
                case STROKE_TYPE_TEXT:
                    if (record.text != null) {
                        TextPaint tp = new TextPaint();
                        tp.setTextSize(record.textSize);
                        tp.setColor(record.color);
                        StaticLayout layout = new StaticLayout(record.text, tp, record.textWidth, Layout.Alignment.ALIGN_NORMAL, 1.0F, 0.0F, true);
                        tempCanvas.translate(record.textOffX, record.textOffY);
                        layout.draw(tempCanvas);
                        tempCanvas.translate(-record.textOffX, -record.textOffY);
                    }
                    Log.e(TAG, "*2* drawPath: ---->drawPath STROKE_TYPE_TEXT");
                    break;

            }
        }
        Log.e(TAG, "*2* drawBitmap: ---->drawBitmap tempBitmap before");
        canvas.drawBitmap(tempBitmap, new Rect(0, 0, tempCanvas.getWidth(), tempCanvas.getHeight()), new Rect(0, 0, canvas.getWidth(), canvas.getHeight()), null);
        Log.e(TAG, "*2* drawBitmap: ---->drawBitmap tempBitmap after");
    }
}

调用界面代码

public class WhiteBoardActivity extends BaseActivity {
    //start 画板相关

    @BindView(R.id.sketch_view)
    SketchView mSketchView;


    @BindView(R.id.whiteboad_root_content)
    View rootView;

    private List<SketchData> sketchDataList = new ArrayList<>();

    private static final int SKETCHVIEW_RECORDDATA_TAG = 0x9001;
    private static final int CLEAR_SKETCHVIEW_RECORDDATA_TAG = 0x9002;
    private Handler sketchViewhandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);

            String sketchDataJSON = (String) msg.obj;
            switch (msg.what){
                case SKETCHVIEW_RECORDDATA_TAG:
                    SketchData curSketchData = GsonUtil.GsonToBean(sketchDataJSON,SketchData.class);
                    if (curSketchData!=null){
                        if (curSketchData.strokeRecordList.size() == 0 && curSketchData.strokeRedoList.size() == 0){
                            mSketchView.erase();
                            return;
                        }
                        mSketchView.setSketchData(curSketchData);
                        mSketchView.invalidate();
                    }
                    break;
                case CLEAR_SKETCHVIEW_RECORDDATA_TAG:
                    Log.d(TAG,"收到关闭画板指令--->"+sketchDataJSON);
                    SketchData clearSketchData = GsonUtil.GsonToBean(sketchDataJSON,SketchData.class);
                    if (clearSketchData!=null){

                        mSketchView.erase();
                        rootView.setVisibility(View.GONE);
                    }

                    activity.finish();
                    break;
            }
        }
    };
    //画板相关 end



    private WhiteBoardReceiver whiteBoardReceiver;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_white_board);
        ButterKnife.bind(this);

        //start 画板
        initWhiteBoard();
        //画板 end

        whiteBoardReceiver = new WhiteBoardReceiver();
        IntentFilter intentFilter = new IntentFilter();
        //intentFilter.addAction(Constant.ACTION_CLEAR_WHITE_BOARD);//已舍弃 归入SEND_SKETCHDATA_WHITE_BOARD
        intentFilter.addAction(Constant.ACTION_UNSYNCHROU);
        intentFilter.addAction(Constant.ACTION_CLOSE_WHITE_BOARD);
        intentFilter.addAction(Constant.SEND_SKETCHDATA_WHITE_BOARD);

        registerReceiver(whiteBoardReceiver, intentFilter);

    }


    //画板 start

    private void initWhiteBoard(){
        initWhiteBoardData();
    }

    private void initWhiteBoardData() {
        SketchData newSketchData = new SketchData();
        sketchDataList.add(newSketchData);
        mSketchView.setSketchData(newSketchData);
    }


    //画板 end


    @Override
    protected void onDestroy() {
        unregisterReceiver(whiteBoardReceiver);
        whiteBoardReceiver = null;
        super.onDestroy();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            return true;
        }
        return false;
    }

    public class WhiteBoardReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            Log.v("PDFMiNaReceiver", "onReceive");
            if (intent != null && intent.getAction() != null && intent.getAction().equals(Constant.ACTION_UNSYNCHROU)) {
                Log.e("ss", "解除同步");
                activity.finish();
            } else if (intent != null && intent.getAction() != null && intent.getAction().equals(Constant.ACTION_CLOSE_WHITE_BOARD)) {
                Log.d(TAG,"收到关闭画板指令");
                String sketchDataJSON = intent.getStringExtra("SKETCHDATA");
                if (sketchDataJSON!=null){
                    Message msg = new Message();
                    msg.what = CLEAR_SKETCHVIEW_RECORDDATA_TAG;
                    msg.obj = sketchDataJSON;
                    sketchViewhandler.sendMessage(msg);
                }
            }else if(intent != null && intent.getAction() != null && intent.getAction().equals(Constant.SEND_SKETCHDATA_WHITE_BOARD)){
                String sketchDataJSON = intent.getStringExtra("SKETCHDATA");
                if (sketchDataJSON!=null){
                    Message msg = new Message();
                    msg.what = SKETCHVIEW_RECORDDATA_TAG;
                    msg.obj = sketchDataJSON;
                    sketchViewhandler.sendMessage(msg);
                }
            }
        }
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 211,948评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,371评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,490评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,521评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,627评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,842评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,997评论 3 408
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,741评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,203评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,534评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,673评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,339评论 4 330
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,955评论 3 313
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,770评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,000评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,394评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,562评论 2 349