Avalonia: window flickers on mac

Created on 17 Aug 2020  路  20Comments  路  Source: AvaloniaUI/Avalonia

My app has bursts of the app window flickering on mac. It looks like the whole window is not drawn for just a frame as you can very briefly see what ever is behind. It gets worse as the app works harder. I see it on a late 2008 macbook pro and a user has reported it on a late 2012 macbook pro on Catalina 10.15.3

Most helpful comment

@jenswet thanks for that useful information. Firstly be reassured, we will not be releasing without resolving this issue.

We have a strategy on how we are going to do it... but probably will prob take a few more weeks before we have something ready.

Not sure how to get more debugging... perhaps using either XCode or Instruments?

All 20 comments

My app has bursts of the app window flickering on mac. It looks like the whole window is not drawn for just a frame as you can very briefly see what ever is behind. It gets worse as the app works harder. I see it on a late 2008 macbook pro and a user has reported it on a late 2012 macbook pro on Catalina 10.15.3

Hi, I have a similar problem with you.
window flickers,also on window,But not every time, and I'm curious as to why

Just checked on the current master. The flickering gets worse as you make the window larger, everything other than the top bar of the window flickers. cpu use appears much higher on osx than other platforms and that appears to be connected to refreshing the screen rather than the rest of the app, I wonder if that is connected.

This is often caused by the render thread throwing exceptions. If you were on windows/Visual Studio, you can see if this is happening by disabling "Just My Code" - not sure how to do it on a mac?

Is this happening for either of you? If so, exception details/stacktrace should help us diagnose it.

I managed to set "JustMyCode" to false in launch.json in vscode on my mac and got no exceptions whilst flickering. On windows I get no exceptions and no flickering.

would a repro help or is there an idea as to what the problem is?

This is often caused by the render thread throwing exceptions. If you were on windows/Visual Studio, you can see if this is happening by disabling "Just My Code" - not sure how to do it on a mac?

Is this happening for either of you? If so, exception details/stacktrace should help us diagnose it.

Hi,I have do it,but i use event.when i close the winfow,.
protected override void OnClosing(CancelEventArgs e)
{
this.Hide();
base.OnClosing(e);
}

@kekekeks this repros in many OS X apps. Resizing etc. Is it possible to present ui when render hasn't yet completed? Btw it's worse with box shadows, but still happens without.

In my app the flickering gets worse the larger the window is. Below a certain size the flickering stops. It does feel like something is running out of time or resources during a frame.

@danwalmsley can we drop Metal-incapable systems? Metal itself is available from OSX 10.11 and is strictly required starting from 10.14.

I think that limits it to 2012 macs and later, it would write off my freebe 2008 test machine but that is not strictly supported by 10.13 (minimum for netcore3) so I can't complain. It would mean dropping support for the some 2009 and all 2010 and 2011 machines. I don't know how may of these are still in use but they are still very useable. I don't recall any of my users mentioning anything pre 2012.

Wasabi and .net core only support officially 10.13+ so let's do it.

I'm looking for a quick temporary fix for this, I have a feeling/hunch that the problem may have appeared when the real fps went from 30 to 60 fps, I'll try a 30 fps render timer on osx but would welcome any suggestions/advice/guesses on any other work arounds as my app is currently not useable on mac

running with a 30fps render timer reduces this from almost continuous flicker when full screen to an occasional flicker. At 10fps I saw no flicker.

I can reproduce the same. Is there any workaround available already?

I use this in BuildAvaloniaApp() to reduce fps to 30 which helps, I tried turning gpu off but cpu was too high for my use.

if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                var wp = builder.WindowingSubsystemInitializer;
                return builder.UseWindowingSubsystem(() =>
                {
                    wp();
                    AvaloniaLocator.CurrentMutable.Bind<IRenderTimer>().ToConstant(new DefaultRenderTimer(30));
                });
            }

            return builder;

I use this in BuildAvaloniaApp() to reduce fps to 30 which helps, I tried turning gpu off but cpu was too high for my use.

if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                var wp = builder.WindowingSubsystemInitializer;
                return builder.UseWindowingSubsystem(() =>
                {
                    wp();
                    AvaloniaLocator.CurrentMutable.Bind<IRenderTimer>().ToConstant(new DefaultRenderTimer(30));
                });
            }

            return builder;

Hi man,.i use your code,On Debian, the feel is ok.
But still flicker occasionally, appear black back figure
This is a serious problem. I want to keep following up.

Hi @danwalmsley @kekekeks @grokys I tried recording some error log, but I didn't succeed.

When debugging with Rider and enabling debugging external code (https://www.jetbrains.com/help/rider/Debugging_External_Code.html) no exception or log output occurs.

When using Visual Studio for Mac with enabled exception tracking in external code I can't see any error either. But the app crashes very often after a few seconds with the flickering. macOS reports the following reason:

abort() called
dotnet(94980,0x70000f89f000) malloc: *** error for object 0x7fa06a098ca0: pointer being freed was not allocated

Can I enable any further logging to help debugging this issue? It would be great to fix this with the 0.10 release if possible.

Thank you!

@jenswet thanks for that useful information. Firstly be reassured, we will not be releasing without resolving this issue.

We have a strategy on how we are going to do it... but probably will prob take a few more weeks before we have something ready.

Not sure how to get more debugging... perhaps using either XCode or Instruments?

@danwalmsley Is there any option to enable logging for the render thread?

Thank you for including this issue in the plan for the next release!

Its a synchronisation issue... we are moving to use MTKView (https://developer.apple.com/documentation/metalkit/mtkview) to fix the issue. This will allow us to synchronise the rendering to the window.

If you are familiar with OSX frameworks and objective c... get in touch and have a go at implementing... otherwise we are waiting for @kekekeks to get round to looking into it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CreateLab picture CreateLab  路  3Comments

MiKaMaru picture MiKaMaru  路  4Comments

kekekeks picture kekekeks  路  4Comments

khoshroomahdi picture khoshroomahdi  路  4Comments

JonathaN7Shepard picture JonathaN7Shepard  路  4Comments