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

OpacityMask is broken, results in NullReferenceException #6446

Closed
yankun opened this issue Aug 19, 2021 · 1 comment
Closed

OpacityMask is broken, results in NullReferenceException #6446

yankun opened this issue Aug 19, 2021 · 1 comment

Comments

@yankun
Copy link
Contributor

yankun commented Aug 19, 2021

Describe the bug
I tried to use an opacity mask, everything worked fine in the Preview as expected (Rider). But running the application, causes a null reference exception. I can reproduce this behaviour under Mac OS and Linux:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Avalonia.Rendering.DeferredRenderer.Avalonia.Rendering.IVisualBrushRenderer.GetRenderTargetSize(IVisualBrush brush) in /_/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs:line 263
   at Avalonia.Skia.DrawingContextImpl.ConfigureVisualBrush(PaintWrapper& paintWrapper, IVisualBrush visualBrush, IVisualBrushRenderer visualBrushRenderer, IDrawableBitmapImpl& tileBrushImage) in /_/src/Skia/Avalonia.Skia/DrawingContextImpl.cs:line 763
   at Avalonia.Skia.DrawingContextImpl.CreatePaint(SKPaint paint, IBrush brush, Size targetSize, Boolean disposePaint) in /_/src/Skia/Avalonia.Skia/DrawingContextImpl.cs:line 899
   at Avalonia.Skia.DrawingContextImpl.PushOpacityMask(IBrush mask, Rect bounds) in /_/src/Skia/Avalonia.Skia/DrawingContextImpl.cs:line 536
   at Avalonia.Rendering.SceneGraph.VisualNode.BeginRender(IDrawingContextImpl context, Boolean skipOpacity) in /_/src/Avalonia.Visuals/Rendering/SceneGraph/VisualNode.cs:line 328
   at Avalonia.Rendering.DeferredRenderer.Render(IDrawingContextImpl context, VisualNode node, IVisual layer, Rect clipBounds) in /_/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs:line 410
   at Avalonia.Rendering.DeferredRenderer.Render(IDrawingContextImpl context, VisualNode node, IVisual layer, Rect clipBounds) in /_/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs:line 427
   at Avalonia.Rendering.DeferredRenderer.Render(IDrawingContextImpl context, VisualNode node, IVisual layer, Rect clipBounds) in /_/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs:line 427
   at Avalonia.Rendering.DeferredRenderer.Render(IDrawingContextImpl context, VisualNode node, IVisual layer, Rect clipBounds) in /_/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs:line 427
   at Avalonia.Rendering.DeferredRenderer.Render(IDrawingContextImpl context, VisualNode node, IVisual layer, Rect clipBounds) in /_/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs:line 427
   at Avalonia.Rendering.DeferredRenderer.RenderToLayers(Scene scene) in /_/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs:line 455
   at Avalonia.Rendering.DeferredRenderer.UpdateRenderLayersAndConsumeSceneIfNeeded(IDrawingContextImpl& context, Boolean recursiveCall) in /_/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs:line 359
   at Avalonia.Rendering.DeferredRenderer.Render(Boolean forceComposite) in /_/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs:line 304
   at Avalonia.Rendering.DeferredRenderer.Paint(Rect rect) in /_/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs:line 224
   at Avalonia.Controls.TopLevel.HandlePaint(Rect rect) in /_/src/Avalonia.Controls/TopLevel.cs:line 333
   at Avalonia.Native.WindowBaseImpl.WindowBaseEvents.Avalonia.Native.Interop.IAvnWindowBaseEvents.Paint() in /_/src/Avalonia.Native/WindowImplBase.cs:line 172
   at Avalonia.Native.Interop.Impl.__MicroComIAvnWindowBaseEventsVTable.Paint(IntPtr this) in /_/src/Avalonia.Native/Interop.Generated.cs:line 3055
--- End of stack trace from previous location ---
   at Avalonia.Native.PlatformThreadingInterface.RunLoop(CancellationToken cancellationToken) in /_/src/Avalonia.Native/PlatformThreadingInterface.cs:line 59
   at Avalonia.Threading.Dispatcher.MainLoop(CancellationToken cancellationToken) in /_/src/Avalonia.Base/Threading/Dispatcher.cs:line 61
   at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(String[] args) in /_/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs:line 116
   at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime[T](T builder, String[] args, ShutdownMode shutdownMode) in /_/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs:line 148
   at Opacity.Program.Main(String[] args) in ... 

To Reproduce
Place this snippet in a fresh application, to crash it. Preview in Rider will display it just fine (a pixelated red dot, depending on you preview / window size).

    <Rectangle Fill="red">
        <Rectangle.OpacityMask>
            <VisualBrush>
                <VisualBrush.Visual>
                    <Ellipse Width="30" Height="30" Fill="black"></Ellipse>
                </VisualBrush.Visual>
            </VisualBrush>
        </Rectangle.OpacityMask>
    </Rectangle>

Expected behavior
The ellipse should work as an opacity mask and render the red fill of the rectangle visible.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Mac OS / Linux
  • Version 10.15 / Ubuntu 20.04
@yankun yankun added the bug label Aug 19, 2021
@yankun
Copy link
Contributor Author

yankun commented Aug 19, 2021

Seems like, this is a duplicate off #2889

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

No branches or pull requests

3 participants