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

[BUG] MediaElement Crash Android #2423

Open
2 tasks done
Pmr-precure opened this issue Jan 3, 2025 · 5 comments
Open
2 tasks done

[BUG] MediaElement Crash Android #2423

Pmr-precure opened this issue Jan 3, 2025 · 5 comments
Labels
bug Something isn't working unverified

Comments

@Pmr-precure
Copy link

Pmr-precure commented Jan 3, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

Current Behavior

Hi,

I have a weird issue, I dispose my mediaelements manually because of other issues.

But now im starting to get this crash:
Image

This is the dispose method of the MediaControlService.Android. It doesnt get called by the DisconnectHandler method, but seems to get randomly called. Since it seems to happen random i havnt been able to replicate. But it causes a lot of crashes in our app.

**
EDIT**

I finally managed to replicate the issue, and it seems to be because of the Garbage Collector.

Our App is using Bluetooth and doing a lot of data processing, so the GC is working hard.
And at somepoint the GC apparently "kills" the MediaSession which leads to this crash ( Eventhough the media service should have been disposed already) .
In this repo https://github.com/Pmr-precure/MauiTestProject/tree/Audio_And_Session_Dispose_Bug
i added a "MemoryFiller" so after starting the video by pressing "Click me", then go back to the homepage and start the memory filler. The crash will happen seconds later.

I think this issue could be the same? #2359

Expected Behavior

Not randomly crash.

Steps To Reproduce

Git clone
Run project
Press the button, and see it crash.

Link to public reproduction project repository

Git repo

Environment

- .NET MAUI CommunityToolkit:10.0.0
- OS: Android
- .NET MAUI: 9.0.21

Anything else?

No response

@Pmr-precure Pmr-precure added bug Something isn't working unverified labels Jan 3, 2025
Copy link
Contributor

Hi @Pmr-precure! We have added the needs reproduction label to this issue, which indicates that we are unable to take further action until you provide a reproduction sample that we can use to reproduce + fix your bug. In accordance with the Reporting a bug section of our Contributing.md that you confirmed reading before you submitted this Issue, we ask that every Issue author provide a link to an open-source repository containing the reproduction sample app. This issue will be closed automatically in 5 days if we do not receive a reproduction sample from you. Please feel free to re-open this Issue once you have provided a reproduction sample.

@Pmr-precure
Copy link
Author

Pmr-precure commented Jan 9, 2025

Only way i have been able to fix this issue is to add GC.SupressFinalize(this) in the dispose method of the MediaControlService. And then call dispose(true) from the onDestroy() method. No idea if this is the fix or not.

Or simply just remove the mediaSession.Release() and Dispose since it seems like its already disposed from somewhere else. :)

Image

Image

@cagriy
Copy link

cagriy commented Jan 13, 2025

I am having a very similar issue. I was disposing of the media element myself as well to avoid memory leaks in IOS; however, on Android, I get this very same crash regardless of whether I dispose of it or not.

When I leave the page where MediaElement lives, all seems fine, but if I call GC.Collect(), the application crashes with this exception.

EDIT: 4.1.2 on .NET 9 doesn't have this issue. Something in 5.0.0 could be introducing this problem.

@Pmr-precure
Copy link
Author

I am having a very similar issue. I was disposing of the media element myself as well to avoid memory leaks in IOS; however, on Android, I get this very same crash regardless of whether I dispose of it or not.

When I leave the page where MediaElement lives, all seems fine, but if I call GC.Collect(), the application crashes with this exception.

EDIT: 4.1.2 on .NET 9 doesn't have this issue. Something in 5.0.0 could be introducing this problem.

Yes i can confirm the crash doesnt happen on 4.1.2.

@ne0rrmatrix
Copy link
Contributor

Can you test the sample app with current main branch. The media 3 PR was just merged a few hours ago. It should solve most issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working unverified
Projects
None yet
Development

No branches or pull requests

4 participants