sdabet
sdabet

Reputation: 18670

SurfaceView crash

In my app I randomly get the following crash:

java.lang.NullPointerException
android.view.SurfaceView.updateWindow(SurfaceView.java:498)
android.view.SurfaceView.updateWindow(SurfaceView.java:412)
android.view.SurfaceView.access$000(SurfaceView.java:89)
android.view.SurfaceView$1.handleMessage(SurfaceView.java:131)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loop(Looper.java:130)
android.app.ActivityThread.main(ActivityThread.java:3691)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:507)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
dalvik.system.NativeStart.main(Native Method)

(Android 2.3.6)

Does anyone have a clue on how to debug it ?

Note that I need to do some weird stuff on my surface to keep it alive when being detached from hierarchy, like:

    private boolean detachFromParent = false;

    @Override
    protected void onDetachedFromWindow() {
        if(detachFromParent) {
            super.onDetachedFromWindow();
        }
    }

    public void destroy() {
        if(getParent() != null) {
            detachFromParent = true;
            ((ViewGroup) getParent()).removeView(this);
            detachFromParent = false;
        }
    }

Upvotes: 2

Views: 2230

Answers (1)

petey
petey

Reputation: 17140

Taking a look at line 498 on the android source (for 2.3.6) for SurfaceView yields:

visible ? VISIBLE : GONE, false, mWinFrame, mContentInsets,

One of these is null, I'm guessing those weird things you are doing is making this code run with mWinFrame value of null.

Can you provide some more detail as to why your not letting the view detach normally? I know you must have a reason. Otherwise, I'd blindly recommend taking it out and afford your intended actions some other way (code it differently).

If you have a Nexus S you could try to debug the issue yourself and figure out the exact root cause of the problem and fix it (stack traces are your friend). Here is a link to instructions on downgrading a Nexus S to 2.3.6

Upvotes: 1

Related Questions