Skiasharp: [BUG] iOS OutOfMemory crash when SKCanvasView height or width less than 1

Created on 15 Jan 2019  路  3Comments  路  Source: mono/SkiaSharp

This situation may occur when SKCanvasView involved in animation
For example:

var ani = new Animation(x => _canvas.HeightRequest = x,_open ? 100 : 0,_open ? 0 : 100); ani.Commit(_stack, "sdfs", length: 2000);
Demo project is attached

  • Version with issue: 1.68.0
  • IDE: Visual Studio 15.9.3

    • iOS: 12.2.1.11

I work around this issue added the custom renderer:

`[assembly: ExportRenderer(typeof(SKCanvasView), typeof(CoreXF.iOS.MySKCanvasViewRenderer))]
namespace CoreXF.iOS
{

public class  MySKCanvasView : SkiaSharp.Views.iOS.SKCanvasView
{
    public override void Draw(CGRect rect)
    {
        if(rect.Height < 1 || rect.Width < 1)
        {
            Debug.WriteLine($"Canvas {rect.Height}x{rect.Width},   Bounds {Bounds.Height}x{Bounds.Width}");
            Debug.WriteLine($"Skip !!");
            return;
        }

        base.Draw(rect);
    }
}

public class MySKCanvasViewRenderer : SKCanvasViewRenderer
{

    public MySKCanvasViewRenderer() : base()
    {
    }
    protected override SkiaSharp.Views.iOS.SKCanvasView CreateNativeControl()
    {
        return new MySKCanvasView();
    }

}

}

Log for this renderer :
[0:] Canvas 0.5x44, Bounds 0.479999999999997x44
[0:] Skip !!

Exception log

Unhandled Exception
System.OutOfMemoryException: Out of memory
2019-01-15 14:47:16.423281+0300 App11.iOS[30640:979369] 
Unhandled Exception:
OutOfMemoryException
2019-01-15 14:47:16.424202+0300 App11.iOS[30640:979369] Unhandled managed exception:
Out of memory (System.OutOfMemoryException)
  at (wrapper managed-to-native) System.Runtime.InteropServices.Marshal.ReAllocCoTaskMem(intptr,int)
  at SkiaSharp.Views.iOS.SKDrawable.CreateSurface (CoreGraphics.CGRect contentsBounds, System.nfloat scale, SkiaSharp.SKImageInfo& info) [0x00080] in <1dff7dabaada4d38b0d12baee26f046c>:0 
  at SkiaSharp.Views.iOS.SKCanvasView.Draw (CoreGraphics.CGRect rect) [0x00040] in <1dff7dabaada4d38b0d12baee26f046c>:0 
  at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.11/src/Xamarin.iOS/UIKit/UIApplication.cs:79 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0002c] in /Library/Frameworks/Xamarin.iOS.fr
amework/Versions/12.2.1.11/src/Xamarin.iOS/UIKit/UIApplication.cs:63 
  at App11.iOS.Application.Main (System.String[] args) [0x00001] in c:\users\vlkam\Source\Repos\App11\App11.iOS\Main.cs:17
2019-01-15 14:47:16.424957+0300 App11.iOS[30640:979369] critical: Stacktrace:
2019-01-15 14:47:16.425120+0300 App11.iOS[30640:979369] critical: 
Native stacktrace:
2019-01-15 14:47:16.449975+0300 App11.iOS[30640:979369] critical:   0   App11.iOS                           0x000000010d9b8134 mono_handle_native_crash + 244
2019-01-15 14:47:16.450203+0300 App11.iOS[30640:979369] critical:   1   libsystem_platform.dylib            0x000000011dfb0b3d _sigtramp + 29
2019-01-15 14:47:16.450330+0300 App11.iOS[30640:979369] critical:   2   ???                                 0x000000010dfe3a22 0x0 + 4529732130
2019-01-15 14:47:16.450433+0300 App11.iOS[30640:979369] critical:   3   libsystem_c.dylib                   0x000000011dd32c45 abort + 127
2019-01-15 14:47:16.450551+0300 App11.iOS[30640:979369] critical:   4   App11.iOS                           0x000000010dba9fdf xamarin_unhandled_exception_handler + 47
2019-01-15 14:47:16.450668+0300 App11.iOS[30640:979369] critical:   5   App11.iOS                           0x000000010da4ee4e mono_invoke_unhandled_exception_hook + 158
2019-01-15 14:47:16.450775+0300 App11.iOS[30640:979369] critical:   6   App11.iOS                           0x000000010d9b7cfc mono_handle_exception_internal + 6140
2019-01-15 14:47:16.450886+0300 App11.iOS[30640:979369] critical:   7   App11.iOS                      
     0x000000010d9b64f9 mono_handle_exception + 25
2019-01-15 14:47:16.450980+0300 App11.iOS[30640:979369] critical:   8   App11.iOS                           0x000000010d939683 mono_amd64_throw_exception + 131
2019-01-15 14:47:16.451078+0300 App11.iOS[30640:979369] critical:   9   ???                                 0x000000013ce425a7 0x0 + 5316552103
2019-01-15 14:47:16.451181+0300 App11.iOS[30640:979369] critical:   10  ???                                 0x0000000140faba4b 0x0 + 5385140811
2019-01-15 14:47:16.451286+0300 App11.iOS[30640:979369] critical:   11  ???                                 0x0000000140fac3a2 0x0 + 5385143202
2019-01-15 14:47:16.451383+0300 App11.iOS[30640:979369] critical:   12  App11.iOS                           0x000000010d9ca9e1 mono_jit_runtime_invoke + 1441
2019-01-15 14:47:16.451502+0300 App11.iOS[30640:979369] critical:   13  App11.iOS                           0x000000010dab01ef mono_runtime_invoke_checked + 127
2019-01-15 14:47:16.451614+0300 App11.iOS[30640:979369] critical:   1
4  App11.iOS                           0x000000010dab38e3 mono_runtime_invoke + 83
2019-01-15 14:47:16.451749+0300 App11.iOS[30640:979369] critical:   15  App11.iOS                           0x000000010dbb30cd xamarin_invoke_trampoline + 6109
2019-01-15 14:47:16.451904+0300 App11.iOS[30640:979369] critical:   16  App11.iOS                           0x000000010dbba2dd xamarin_arch_trampoline + 189
2019-01-15 14:47:16.452098+0300 App11.iOS[30640:979369] critical:   17  App11.iOS                           0x000000010dbbb711 xamarin_x86_64_common_trampoline + 110
2019-01-15 14:47:16.452307+0300 App11.iOS[30640:979369] critical:   18  UIKitCore                           0x0000000126953dc6 -[UIView(CALayerDelegate) drawLayer:inContext:] + 550
2019-01-15 14:47:16.452496+0300 App11.iOS[30640:979369] critical:   19  QuartzCore                          0x000000011524c729 -[CALayer drawInContext:] + 285
2019-01-15 14:47:16.452614+0300 App11.iOS[30640:979369] critical:   20  QuartzCore                          0x000000011524bc
34 -[CALayer _display] + 937
2019-01-15 14:47:16.452775+0300 App11.iOS[30640:979369] critical:   21  QuartzCore                          0x00000001151ca8ee _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 634
2019-01-15 14:47:16.452910+0300 App11.iOS[30640:979369] critical:   22  QuartzCore                          0x000000011520197e _ZN2CA11Transaction6commitEv + 576
2019-01-15 14:47:16.453091+0300 App11.iOS[30640:979369] critical:   23  QuartzCore                          0x00000001152026fa _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 76
2019-01-15 14:47:16.453289+0300 App11.iOS[30640:979369] critical:   24  CoreFoundation                      0x000000011b803c27 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
2019-01-15 14:47:16.453432+0300 App11.iOS[30640:979369] critical:   25  CoreFoundation                      0x000000011b7fe0be __CFRunLoopDoObservers + 430
2019-01-15 14:47:16.453583+0300 App11.iOS[30640:979369] critical:   26  CoreFoundation                   
   0x000000011b7fe751 __CFRunLoopRun + 1537
2019-01-15 14:47:16.453695+0300 App11.iOS[30640:979369] critical:   27  CoreFoundation                      0x000000011b7fde11 CFRunLoopRunSpecific + 625
2019-01-15 14:47:16.453851+0300 App11.iOS[30640:979369] critical:   28  GraphicsServices                    0x0000000120a7f1dd GSEventRunModal + 62
2019-01-15 14:47:16.453974+0300 App11.iOS[30640:979369] critical:   29  UIKitCore                           0x000000012646a81d UIApplicationMain + 140
2019-01-15 14:47:16.454120+0300 App11.iOS[30640:979369] critical:   30  ???                                 0x0000000140b1f2be 0x0 + 5380371134
2019-01-15 14:47:16.454244+0300 App11.iOS[30640:979369] critical:   31  ???                                 0x0000000140b1f053 0x0 + 5380370515
2019-01-15 14:47:16.454363+0300 App11.iOS[30640:979369] critical: 
=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of t
he native libraries 
used by your application.

Repos.zip

VS bug #770227

area-SkiaSharp.Views type-bug

All 3 comments

Thanks for reporting this. I will investigate all the platforms and fix where needed.

Thank you for the awesome library!

This is going to be fixed in PR #761

Was this page helpful?
0 / 5 - 0 ratings