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

[FIX] Windows CTD on Application Close #2067

Merged

Conversation

ne0rrmatrix
Copy link
Contributor

@ne0rrmatrix ne0rrmatrix commented Jul 29, 2024

Description of Change

Add null checks for MediaElement in update methods. This should resolve the issue with CTD in Windows when closing app.

Linked Issues

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Documentation created or updated: https://github.com/MicrosoftDocs/CommunityToolkit/pulls

Additional information

2 1/2 min video in Windows where MediaElement is playing video and then app is closed randomly to see if it crashes. It does not. The startup issue display at some points in video is unrelated and has been present since Maui went GA. It is not addressed and not related to toolkit.

2024-07-28.21-42-27.mp4

Improved robustness by adding null checks for `MediaElement` in
`PlatformUpdatePosition` and `PlatformUpdateShouldKeepScreenOn`
methods to prevent potential null reference exceptions.
Removed redundant null checks in `PlatformUpdateShouldKeepScreenOn`
to streamline the logic and enhance code readability.
@ne0rrmatrix ne0rrmatrix requested a review from brminnick August 3, 2024 03:34
@ne0rrmatrix ne0rrmatrix self-assigned this Aug 4, 2024
@ne0rrmatrix ne0rrmatrix added the 📽️ MediaElement Issue/PR that has to do with MediaElement label Aug 4, 2024
bijington
bijington previously approved these changes Aug 7, 2024
Copy link
Contributor

@bijington bijington left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor suggestion but feel free to ignore if you prefer the current approach

…ows.cs

Co-authored-by: Shaun Lawrence <shaunrlawrence@gmail.com>
bijington
bijington previously approved these changes Aug 7, 2024
Copy link
Contributor

@bijington bijington left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

Introduced a new `ParentWindow` record struct in the `MediaManager` class to handle null checks for the parent window and its handler. Added a static property `Exists` within `ParentWindow` to perform these checks and log errors if necessary. Updated the `PlatformUpdatePosition` method to return early if the parent window does not exist, preventing position updates when the window is closed. Simplified the `PlatformUpdateShouldKeepScreenOn` method by removing a redundant check for `MediaElement.ShouldKeepScreenOn`.
Introduce MediaManagerWindowsTests in MediaManager.windows.Tests.cs.
Add ParentWindow record struct with static properties CurrentPage
and Exists. Implement four Xunit tests to verify ParentWindow.Exists
behavior under various conditions.
Moved ParentWindow tests from MediaManager.windows.Tests.cs to a new file, ParentWindowTests.cs. Updated and reorganized test cases for ParentWindow.Exists, including scenarios for null parent window, null handler, and null platform view. Introduced MockWindowHandler class for simulating handler behavior. Adjusted using directives and namespace declarations to reflect the new file structure.
Refactored the `ParentWindow` record struct to consolidate its definition within the `PageExtensions` class. This change involved:

- Adding a new `ParentWindow` record struct in `PageExtensions.cs` with static properties `CurrentPage` and `Exists`.
- Removing the `ParentWindow` record struct from `MediaManager.windows.cs` and adding a `using` directive to import it from `CommunityToolkit.Maui.Extensions.PageExtensions`.
- Removing the `ParentWindow` record struct from `ParentWindowTests.cs` and adding a `using` directive to import it from `CommunityToolkit.Maui.Extensions.PageExtensions`.
- Ensuring the `ParentWindowTests` class retains its test method `Exists_WhenParentWindowIsNull_ReturnsFalse` to verify the `Exists` property behavior.
Simplified GetCurrentPage call in PageExtensions.cs.
Changed ParentWindow struct visibility to internal.
Refactored ParentWindowTests.cs for better readability.
Added MockWindowHandler class for IElementHandler mocking.
@ne0rrmatrix ne0rrmatrix requested a review from bijington August 8, 2024 07:30
@ne0rrmatrix ne0rrmatrix enabled auto-merge (squash) August 8, 2024 22:45
@ne0rrmatrix ne0rrmatrix merged commit 397d091 into CommunityToolkit:main Aug 8, 2024
7 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
📽️ MediaElement Issue/PR that has to do with MediaElement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Media Element Windows Crash on Exit
3 participants