Skip to content

Problem in FboSkiaSurface initializatoin #19092

Open
@vadimart92

Description

@vadimart92

Describe the bug

I am investigating app crash because of AccessViolationException:

Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Stack: 
at SkiaSharp.SkiaApi.<gr_direct_context_flush_and_submit>g__{}PInvoke|27_0(IntPtr, SByte) 
at SkiaSharp.SkiaApi.<gr_direct_context_flush_and_submit>g{}{}PInvoke|27_0(IntPtr, SByte) 
at Avalonia.Skia.SurfaceRenderTarget.Blit(Avalonia.Platform.IDrawingContextImpl) 
at Avalonia.Rendering.Composition.Server.ServerCompositionTarget.Render()
at Avalonia.Rendering.Composition.Server.ServerCompositor.RenderCore(Boolean) 

there is a problem in FboSkiaSurface constructor I guess:

var target = new GRBackendRenderTarget(pixelSize.Width, pixelSize.Height, 0, 8,
new GRGlFramebufferInfo((uint)_fbo, SKColorType.Rgba8888.ToGlSizedFormat()));
_surface = SKSurface.Create(_grContext, target,
surfaceOrigin, SKColorType.Rgba8888, new SKSurfaceProperties(SKPixelGeometry.RgbHorizontal));
CanBlit = gl.IsBlitFramebufferAvailable;

Since GRBackendRenderTarget has a finalizer and calls gr_backendrendertarget_delete in its Dispose method, it will be invoked as soon as the target is garbage collected (and it will be, because SKSurface doesn't hold a reference to the target).

I am not sure but running such code from finalizer (separate thread) may crash app

To Reproduce

I don't have any repro now

Expected behavior

No response

Avalonia version

11.3.0

OS

Windows

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions