Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After upgrading too Xamarin.Forms 4 Or Using Fast Renderer getting exception #45

Closed
PWaliaDev opened this issue Jul 2, 2019 · 13 comments · Fixed by #53
Closed

After upgrading too Xamarin.Forms 4 Or Using Fast Renderer getting exception #45

PWaliaDev opened this issue Jul 2, 2019 · 13 comments · Fixed by #53

Comments

@PWaliaDev
Copy link

I upgraded Xamarin.Forms to 4.0.0 service request and then getting exception

No constructor found for Xamarin.Forms.Platform.Android.FastRenderers.ImageRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership)

Unable to activate instance of type Xamarin.Forms.Platform.Android.FastRenderers.ImageRenderer from native handle 0xbfd3900c (key_handle 0xcbe3ef).

StackTrace:

at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00182] in :0
at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x000c1] in :0
at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00017] in :0
at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in :0
at Java.Lang.Object.GetObject[T] (System.IntPtr jnienv, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00006] in :0
at Android.Views.View.n_Invalidate (System.IntPtr jnienv, System.IntPtr native__this) [0x00000] in :0
at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.76(intptr,intptr)

Source: Mono.Android

System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.FastRenderers.ImageRenderer from native handle 0xbfd3900c (key_handle 0xcbe3ef). ---> System.MissingMethodException: No constructor found for Xamarin.Forms.Platform.Android.FastRenderers.ImageRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
at Java.Lang.Error: Exception of type 'Java.Lang.Error' was thrown.
at java.lang.Error: Java callstack:
at at md5f92e0daf340890c9667469657ee2ece8.ImageRenderer.n_invalidate(Native Method)
at at md5f92e0daf340890c9667469657ee2ece8.ImageRenderer.invalidate(:54)
at at android.widget.ImageView.invalidateDrawable(ImageView.java:281)
at at android.graphics.drawable.Drawable.invalidateSelf(Drawable.java:450)
at at android.graphics.drawable.Drawable.setVisible(Drawable.java:859)
at at android.widget.ImageView.updateDrawable(ImageView.java:1011)
at at android.widget.ImageView.setImageDrawable(ImageView.java:567)
at at com.bumptech.glide.request.target.DrawableImageViewTarget.setResource(:28)
at at com.bumptech.glide.request.target.DrawableImageViewTarget.setResource(:10)
at at com.bumptech.glide.request.target.ImageViewTarget.setResourceInternal(:127)
at at com.bumptech.glide.request.target.ImageViewTarget.onResourceReady(:104)
at at com.bumptech.glide.request.SingleRequest.onResourceReady(:579)
at at com.bumptech.glide.request.SingleRequest.onResourceReady(:549)
at at com.bumptech.glide.load.engine.EngineJob.handleResultOnMainThread(:218)
at at com.bumptech.glide.load.engine.EngineJob$MainThreadCallback.handleMessage(:324)
at at android.os.Handler.dispatchMessage(Handler.java:102)
at at android.os.Looper.loop(Looper.java:164)
at at android.app.ActivityThread.main(ActivityThread.java:6494)
at at java.lang.reflect.Method.invoke(Native Method)
at at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
--- End of inner exception stack trace ---
at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00055] in :0
at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00116] in :0
--- End of inner exception stack trace ---
at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00182] in :0
at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x000c1] in :0
at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00017] in :0
at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in :0
at Java.Lang.Object.GetObject[T] (System.IntPtr jnienv, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00006] in :0
at Android.Views.View.n_Invalidate (System.IntPtr jnienv, System.IntPtr native__this) [0x00000] in :0
at at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.76(intptr,intptr)

I was also getting this issue when I was using FastRenderer so I skipped to use them but as now FastRenderers are default so getting this issue.

Version with issue:
Last known good version: 3.0.1
IDE:
Platform Target Frameworks:
Android: Xamarin.Android 8.1
Nuget Packages: 4.0.0 Service Request 4
Affected Devices: Android

@jonathanpeppers
Copy link
Owner

@PWaliaDev does this happen if you navigate to a page and stay there?

Or does it only happen at some point after you have navigated away from a page that has an image?

@PWaliaDev
Copy link
Author

PWaliaDev commented Jul 2, 2019

This is happening when pressing back button and app finishing activity.
As well when i install app first time and after login going to dashboard when data is binding inside carousel then this comes.

All screen have images.

This is blocking and stoping to upgrade packages and uploading to play store so need solution as soon as possible

@activa
Copy link

activa commented Aug 19, 2019

I'm having the same issue, but not when navigating to/from pages. It happens when hundreds of images are shown in a list view and scrolling rapidly through the list. ViewCells contain an image and the viewcells are recycled (which is the default for ListView).
It works 90% of the time but sometimes the app crashes with the exception shown above. I will try to create a test project that demonstrates the issue.

@jonathanpeppers
Copy link
Owner

@activa if you can get a project to show the problem that would help so much! You could also add a page to the sample in this repo if that is easy enough.

@jonathanpeppers
Copy link
Owner

@activa any luck getting a repro?

I tried this ListViewOfDoom page, which unfortunately works fine: #51

I tried putting a large image from a URL into an ImageCell and scrolling a lot -- should I try something else? The random number in the URL forces Glide to re-download on each row.

@activa
Copy link

activa commented Aug 21, 2019

@jonathanpeppers I haven't had time to do that yet. However, after playing with our app a little bit, I noticed that I have never been able to trigger the exception in debug mode. In release mode it's very easy to reproduce though.

@jonathanpeppers
Copy link
Owner

@activa my example seems to work in Release mode, too. Let me know if you can send me an example that breaks...

If I fixed this bug, it would be enough to push out another release of glidex.forms.

@activa
Copy link

activa commented Sep 23, 2019

@jonathanpeppers I finally have some time this afternoon to try and reproduce it. I will try to make it fail using your "ListView of doom" sample.

@activa
Copy link

activa commented Sep 23, 2019

It was pretty easy to reproduce (almost 100% reproducible):

In your ListView Of Doom sample, change the ListView to use larger images and use a standard ViewCell:

    <ListView ItemsSource="{Binding}" CachingStrategy="RecycleElement" RowHeight="200">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <Image Source="{Binding}"/>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

When running this, scroll through the list very fast and tap the "Back" button while it's still scrolling. 90% of the time it will crash with the exception mentioned in this issue.

jonathanpeppers added a commit that referenced this issue Sep 24, 2019
Fixes: #45

Thanks @activa! I could finally reproduce this!

The problem here is we need to cancel any in-flight Glide requests
when the `ImageRenderer` is disposed. Otherwise, Java completes the
request against a C# object that is no longer alive.

There may be a future fix needed here for `ImageCell`, but I wasn't
able to reproduce a problem there.
jonathanpeppers added a commit that referenced this issue Sep 24, 2019
Fixes: #45

Thanks @activa! I could finally reproduce this!

The problem here is we need to cancel any in-flight Glide requests
when the `ImageRenderer` is disposed. Otherwise, Java completes the
request against a C# object that is no longer alive.

There may be a future fix needed here for `ImageCell`, but I wasn't
able to reproduce a problem there.
@activa
Copy link

activa commented Sep 24, 2019

@jonathanpeppers I pulled the latest code from the master branch and the issue still remains. It's 100% reproducible and it throws the exact same exception:

System.NotSupportedException: 'Unable to activate instance of type Xamarin.Forms.Platform.Android.FastRenderers.ImageRenderer from native handle 0x7fe80b7824 (key_handle 0x82c9026).'

I'm simply running your ListView of Doom sample, scroll quickly and while it's scrolling, tap back.

@activa
Copy link

activa commented Sep 24, 2019

Ok, never mind. For some reason pulling the latest code didn't update the glidex.forms.csproj file so the new FastRenderer class was not added to the project.

It seems to work fine now.

@jonathanpeppers
Copy link
Owner

2.0.0.236 is also on NuGet now, so you should be able to start using it in your app.

@activa
Copy link

activa commented Sep 26, 2019

Everything's working great with 2.0.0.236. Thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants