How to handle or prevent the fatal error “Fatal signal 11 (SIGSEGV)”

泪湿孤枕 提交于 2019-12-25 02:19:24

问题


Perhapse I am lucky on the fatal error on different signals. For today that was the following:

02-05 20:57:21.827: D/MY_TEST_MESSAGE(4349): Engine.onVisibilityChanged()
02-05 20:57:21.827: D/MY_TEST_MESSAGE(4349): DrawTask #3 is created!
02-05 20:57:21.827: D/MY_TEST_MESSAGE(4349): DrawTas #3 is working!
02-05 20:57:21.837: I/brcm-gr(4349): [gralloc_lock]: new usage 0x903
02-05 20:57:21.837: I/brcm-gr(4349): [gralloc_lock]: new usage 0x930
02-05 20:57:21.877: I/brcm-gr(4349): [gralloc_lock]: new usage 0x933
02-05 20:57:21.927: D/dalvikvm(4349): GC_FOR_ALLOC freed 1519K, 18% free 20612K/25095K, paused 31ms, total 31ms
02-05 20:57:21.987: I/brcm-gr(4349): [gralloc_lock]: new usage 0x933
02-05 20:57:22.257: D/MY_TEST_MESSAGE(4349): Engine.onVisibilityChanged()
02-05 20:57:22.347: I/brcm-gr(4349): [gralloc_lock]: new usage 0x933
02-05 20:57:22.427: I/brcm-gr(4349): [gralloc_lock]: new usage 0x903
02-05 20:57:22.427: I/brcm-gr(4349): [gralloc_lock]: new usage 0x930
02-05 20:57:22.447: I/brcm-gr(4349): [gralloc_lock]: new usage 0x933
02-05 20:57:22.497: D/MY_TEST_MESSAGE(4349): Engine.onSurfaceDestroyed()
02-05 20:57:22.507: D/MY_TEST_MESSAGE(4349): Engine.onDestroy released
02-05 20:57:22.517: D/MY_TEST_MESSAGE(4349): WallpaperService.onDestroy()
02-05 20:57:22.627: D/dalvikvm(4349): GC_FOR_ALLOC freed 1510K, 18% free 20619K/25095K, paused 18ms, total 19ms
02-05 20:57:22.627: I/dalvikvm-heap(4349): Grow heap (frag case) to 25.673MB for 5242896-byte allocation
02-05 20:57:22.657: D/dalvikvm(4349): GC_CONCURRENT freed 8K, 16% free 25731K/30279K, paused 3ms+3ms, total 23ms
02-05 20:57:22.727: A/libc(4349): Fatal signal 11 (SIGSEGV) at 0x52905020 (code=2), thread 4376 (AsyncTask #3)

This log snippet say me that, probably, error occured when I try to use SurfaceHolder that actually is destroyed with the onSurfaceDestroyed() method.

The use case of such state is:

  1. start my Live Wallpaper
  2. press on Settings button
  3. change any of settings (or without changing - the same behaviour) and press Back
  4. immediately press Back again
  5. error occured

So, what is up between (4) and (5)? The main point is that after pressing Back on Settings screen the onVisualChanged() method invokes the preset animation for changing images using available holder and canvas, but next immediate pressing Back invokes onSurfaceDestroyed() method that makes holder destroyed.

@"This is only one situation that I could reproduce with an error above."

@"An error does not occured if second pressing of Back will be near to the state animation finished"

So, my questions are:

  1. Is there any technics to handle or prevent arised error?
  2. How can I say my DrawTask that the holder is unavailable and animation should be stopped?
  3. Or, may be there is another cause of this error?

回答1:


Not sure, whether it was done in correct way, but currently I resolved my issue by adding three seconds sleep. So, the onSurfaceDestroyed() has been changed with:

        @Override
    public void onSurfaceDestroyed(SurfaceHolder holder) {
        super.onSurfaceDestroyed(holder);
        Log.d("MY_TEST_MESSAGE", "Engine.onSurfaceDestroyed()");
        try{
             Thread.currentThread().sleep(500);
        }
        catch(Exception ie){ }
        mVisible = false;
        if (myDrawTask != null) {
            myDrawTask.cancel(false);
        }
    }

It works without any unexpected delays.



来源:https://stackoverflow.com/questions/21587598/how-to-handle-or-prevent-the-fatal-error-fatal-signal-11-sigsegv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!