What is causing UWP app to intermittently crash an

2019-08-27 18:29发布

We are developing a UWP application and noticing intermittent crashes when launching the debug process in Visual Studio.

Exception Unhandled
Unhandled exception at 0x00007fff8f9ac10c (Windows.UI.Xaml.dll) in
[ourAppName].exe: 0xC0000005: Access violation reading location
0x0000000000000000

We have also seen a release build of the app crash on launch after sideloading the AppX package onto particular machines but not on others. When a debugger was attached to the process on that machine the error was:

(7ebc.7298): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
Windows_UI_Xaml!CFocusRectManager::GetFocusOptionsForElement+0x158:
00007ff9`43d7c10c 488b01          mov     rax,qword ptr [rcx]
ds:00000000`00000000=????????????????

Our application is a fairly simple two page puzzle game application where the first page is basically a home page that is used to launch the game board.

The first page does display momentarily before the app crashes.

We have tried isolating any of our asynchronous code in the page constructor by commenting it out, but the crash still occurs.

Any thoughts on what might be causing the crashes?

1条回答
来,给爷笑一个
2楼-- · 2019-08-27 19:02

After further experimentation I stumbled upon the problem and have found a super simple repro that demonstrates the cause of the crash and also validates our work around.

The culprit is a button control with the following property setting:

FocusVisualPrimaryBrush="{x:Null}"

To reproduce the problem:

  • create a brand new Windows Universal project of type Blank App (Universal Windows)
  • add a Button to the existing Grid control
<Button HorizontalAlignment="Center" Width="100" Height="100" FocusVisualPrimaryBrush="{x:Null}" />

Note that if you Start Debugging by pressing F5 you may not see the error. However, if you Start without Debugging by hitting Ctrl-F5 the new app will crash a few seconds after it starts.

Our application uses Eye Control so the visible focus rectangle around the first control in the tab order was distracting, so I had set the FocusVisualPrimary in the Properties window to No brush, which was the source of the {x:Null} value in the Xaml definition of the Button.

As a work around I was able to change that one line to:

<Button HorizontalAlignment="Center" Width="100" Height="100" FocusVisualPrimaryBrush="Transparent" />

and the focus rectangle wasn't a distraction and the application stopped crashing.

As a follow up I searched my code for all occurrencesof the FocusVisualPrimaryBrush being set to Null and found a few other instances of it in the app that may have happened due to copy/paste of the original button. Besides crashing at startup, I have also found that tabbing to a control that has FocusVisualPrimaryBrush set to Null will also cause a sudden application crash. I have since either removed or replaced all occurrences of the "{x:Null}" with "Transparent".

查看更多
登录 后发表回答