-
Notifications
You must be signed in to change notification settings - Fork 291
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
Access Violation App Crash #954
Comments
I've found replication steps that work for me 100% of the time. I've investigated the issue and found the root cause - there is a logic error in the way Win2D handles the attach/detach of event handlers of a High-level explanationWin2D attaches/detaches event handlers to a Detailed discoveryOur app renders document pages as a number of tiled segments where each segment uses a I took a fork of the Win2D library and hooked it up to our app. In my local fork:
In our app I did the same:
With the instumentation in place I replicated the error and grabbed all the text in Visual Studio's Output Window. I'm using TextAnalysisTool.NET to work with the output, applying filters and colours. Here's a screen capture showing the series of events leading up to one of the crashes due to an access violation: Some notes about this image:
In this image I've filtered out everything but id 4, which is where the app crashes. Here's an account of what we're seeing here:
At this point in the log it's worth mentioning the // OnLoaded and OnUnloaded are fired from XAML asynchronously, and unfortunately they could
// be out of order. If the element is removed from tree A and added to tree B, we could get
// a Loaded event for tree B *before* we see the Unloaded event for tree A. To handle this:
// * When we see a Loaded event when we're already loaded, just unregister event handlers
// for the old tree and register for the new one.
// * When we get an Unloaded event, check the loaded count. If the element has already been
// added to another tree, the load count will be nonzero. In that case, we don't update
// anything because the OnLoaded call has already taken care of things. However as we've seen so far in this log, UWP has fired the unloaded event without a matching loaded event, putting the counter in a negative value. This is OK for the moment as we can see the event handlers are currently unregistered (line Let's continue the walkthrough. On lines Lines Now things get interesting. Line Lines Line Line Important I've investigated to see if there's anything I can do in our app code to prevent loaded/unloaded events firing out of order, or from firing the unloaded event without a matching loaded event. There is nothing app developer's can do to prevent this, so the suggestions from Win2D on avoiding memory leaks do not apply. Fixing Win2DThere are 34 combinations of loaded/unloaded events (and the occasional unloaded event on it's own) that Win2D must deal with to prevent holding a registered event handler on a finalised object. Currently Win2D is only dealing with 14 of them. I won't put the details of these scenarios here, but have written tests that document and deal with them. Fortunately there is a very simple fix for Win2D to accommodate all possible combinations, by changing 2 lines of code inside the
Contributing to the UWP branchI would prefer that our app (and other UWP apps) use the official Win2D nuget package instead of maintaining private forks with the patched code. I'm happy to create PR including the fix and the unit tests that exercise it. If I contribute such a PR will Microsoft review the change and follow up with a release of Win2D for UWP containing the fix? Or has support for Win2D on UWP officially been dropped? |
I have a crash in my UWP application that is hitting when i switch between portrait and landscape mode.
I haven't been able to find a minimal way to reproduce this in a sample app yet.
I have been able to get the crash under a debugger though.
Here is the stack trace that I get:
The crash is an access violation. I'm also seeing a large number of reports from partner center for similar crashes.
Any idea if this is an issue in win2D?
I figured i'm doing something wrong, but the level of information i'm getting here is very minimal.
Any advice on what I can do to debug this would be greatly appreciated?
The app is a UWP app. I've tested on v 1.26 and v1.27.1 of win2d, and both versions show the crash.
Our app targets 1903 version of windows.
Crash happens on windows 10, and windows 11 devices.
I can reproduce this somewhat reliably (but not 100%). I am able to get a crash dump if that is useful.
The text was updated successfully, but these errors were encountered: