Forum Xamarin.Android

System.ArgumentException 'jObject' must not be IntPtr.Zero thrown only in Android Lollipop

Jordan.9294Jordan.9294 USMember, University

Hi,

I have a problem when trying to recycle my bitmaps. This problem only occurs on Android Lollipop, I've tried on earlier version and the problem never occured. Before calling Recycle(), I check that my bitmap is not null and not already recycled, works fine on Android 4.X but crash on Android 5.X.
The exception is thrown by Android.Runtime.JNIEnv.CallVoidMethod(intptr,intptr). I call Recycle() on my bitmap during OnDetachedFromWindow method.

Did anyone encounter this problem yet? Or am I doing something wrong?

Best Answer

Answers

  • DanPearceDanPearce GBMember

    I get this problem too. Any updates would be appreciated.

  • Jordan.9294Jordan.9294 USMember, University

    Indeed, there is some case I had a using statement that disposed the bitmap right after a block of instructions. Removing the using statement has resolved my problem.

  • Matthew-RobbinsMatthew-Robbins AUInsider ✭✭

    This is a little late to reply but if Bitmap is derived from Java.Lang.Object then calling Dispose will sever the peer connection and set the bitmaps Handle (this links the .NET object to the Java object instance) to IntPtr.Zero.

    Wrapping a Java.Lang.Object derived class inside a using statement will cause Dispose to be automatically called, severing the connection between Mono and Dalvik.

    Just some context on what happened here for future readers/internet searchers :blush:

Sign In or Register to comment.