Open ibocon opened 4 years ago
cc @mattleibow
@rmarinho I am not sure why this would happen. Is this a result of something that needs to be done in a renderer?
This is my renderer:
public class SKCanvasViewRenderer : SKCanvasViewRendererBase<SKFormsView, SKNativeView>
{
public SKCanvasViewRenderer(Context context)
: base(context)
{
}
[EditorBrowsable (EditorBrowsableState.Never)]
[Obsolete("This constructor is obsolete as of version 2.5. Please use SKCanvasViewRenderer(Context) instead.")]
public SKCanvasViewRenderer()
: base()
{
}
protected override SKNativeView CreateNativeControl() =>
GetType() == typeof(SKCanvasViewRenderer)
? new SKNativeView(Context)
: base.CreateNativeControl();
}
The canvas appears on the screen at startup, but when the touch event fires and swaps out the view, Forms disposes it. Then for some reason it starts up again?
A big stack trace: https://gist.github.com/mattleibow/61939af789e7a2133be41d29c846729e
Instead of replacing ContentView.Content
, toggle VisualElement.IsVisible
between SKCanvasView
and Editor
.
<ContentView.Content>
<AbsoluteLayout>
<skia:SKCanvasView x:Name="CanvasView"
AbsoluteLayout.LayoutFlags="All"
AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
IsVisible="True"
EnableTouchEvents="True"/>
<Editor x:Name="EditorView"
AbsoluteLayout.LayoutFlags="All"
AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
IsVisible="False"
AutoSize="TextChanges" />
</AbsoluteLayout>
</ContentView.Content>
public void ToggleState()
{
if (isCanvasView)
{
CanvasView.IsVisible = true;
CanvasView.Focus();
EditorView.IsVisible = false;
EditorView.Unfocus();
}
else
{
CanvasView.IsVisible = false;
CanvasView.Unfocus();
EditorView.IsVisible = true;
EditorView.Focus();
}
}
For cleaner code, State pattern could be a great solution than if
.
Great that you have a workaround. If the forms team notices a bug, then I'll fix it. Hopefully we can get this going nicely soon.
Also encountered this issue and had to work around. Some interaction with an Android renderer and touch. With minor tweaks the error would sometimes appear as System.ObjectDisposedException: Cannot access a disposed object. Object name: '...Renderer'
We use renderers to handle Keyboard input. The workaround ended up OK so we are not depending on a fix for this. Maybe with MAUI handlers having less magic than renderers there will be less chance of running into this in future.
I am also seeing this error when removing a SKCanvasView from Form. The trigger for this exception seems to be a second touch event coming in that has nowhere to go as the .net SKCanvasView has already been disposed. Presumably there is some unfortunate logic that means that when you remove the SKCanvasView in the middle of a touch callback the dispose doesn't push down correctly. You can set the SKCanvasView to invisible and then use Device.BeginInvokeOnMainThread to schedule a later removal.
Description
I am trying to replace
ContnetView.Contnet
by touch.Steps to Reproduce
copy & paste source code
Expected Behavior
MyContnetView.Content
changed.Actual Behavior
System.NotSupportedException
Basic Information
Reproduction Link
Reproduce Project
StackOverflow Link
System.NotSupportedException: 'Undable to activate instance of type SkiaSharp.Views.Forms.SKCanvasViewRenderer from native handle'