-
-
Notifications
You must be signed in to change notification settings - Fork 360
Only one operation can be active at at time #598
Comments
I noticed this error as well in an App Center crash log. It happens when the user taps twice on the button to take the picture. I tried wrapping the call in a try/catch block but the app still crashes. It would be great if it handled the situation, without crashing the app. Here's the error: MediaImplementation.TakeMediaAsync (System.String type, System.String action, Plugin.Media.Abstractions.StoreMediaOptions options) Here's the stack trace: MediaImplementation.TakeMediaAsync (System.String type, System.String action, Plugin.Media.Abstractions.StoreMediaOptions options) |
I still can not fix it :( |
This bug is hitting us too but with a different workflow:
The cause is pretty simple. The media picker uses TaskCompletionSource to turn a callback driven API into Task async/await style. but the code adds a check to make sure that only 1 TaskCompletionSource is active at one time. Each usage of the media picker does the following:
So in my workflow of clicking the Home button in the middle of picking a photo, the user never picked/took a photo so the handler is never called to null out the TaskCompletionSource. By resuming the app using the phone desktop icon, the media picker is lost so when the user tries to launch the media picker a second time, it fails the null check in step 2 above causing an exception to be thrown. So whether you click the button twice or do my workflow, in both cases TaskCompletionSource is not null the second time and the exception is thrown. This needs to be fixed. |
I'm not sure why but I don't see this issue in our production app (was using 4.0.1.1 but also tested upgrading to 4.0.1.5). I did see this issue when re-implementing the image multi-select branch though, the fix I implemented is here, you only need the changes in src/Media.Plugin/iOS/ECLImagePickerViewController.cs. Essentially if you tap outside the modal sometimes the modal is dismissed without hitting the other dismiss paths, I just added on more check when the VC is dismissed. If you need a quick fix you could try building that nuget locally and using it until it gets pulled into master. |
I am experiencing this issue as well, are there any plans on fixing this or has anyone found a workaround |
Following Scastria comment from the bug - jamesmontemagno#598 (comment) If we null out the completionsource on sleep, which will call OnDestry to the media Activity, it fixes the issue
I am hitting this issue on droid ONLY. can be easily reproduced by following the steps - |
i hit this issue when i was launching photo camera intent twice accidentally(fast button presses in emulator). once i debounced the button,the issue went away. library doesn't like it when two photo intents are being called i think |
I am seeing this issue, on the new beta build, which includes the Multi-Select feature. On iOS, clicking outside the popup dismisses it, but the next time you try to launch the Gallery select, you get a popup messages that says "Only one operation can be active at at time." On Android, when the gallery select displays (fullscreen) clicking the onscreen back button or the hardware back button both result in a null exception from the PickPhotosAsync call. |
Fix to - Only one operation can be active at at time #598
I am seeing this issue on the latest version of Media plugin when the user presses home button on iOS. |
I see such error on AppCenter, but I cannot reproduce this problem on my devices and emulators. |
workaround from ctor {
o.Event += async (s,e) => {
await CrossMedia.Current.Initialize();
var file = await CrossMedia.Current.TakePhotoAsync(~~~~~
}
} to ctor {
var t = Task.Run(async () => { await CrossMedia.Current.Initialize(); });
t.Wait();
o.Event += TheEvent;
}
async void TheEvent(s, e) {
var file = await CrossMedia.Current.TakePhotoAsync(~~~~~
}
protected override void OnDisappearing()
{
base.OnDisappearing();
o.Event -= TheEvent;
} |
no need of any workaround to this in your MainActivity " LaunchMode = LaunchMode.SingleTop" example : |
My users are reporting this also.
I will be trying the workaround suggested by @Nullstr1ng , thanks. |
@RhomGit I notice this only happens to my users if they use Samsung Gallery/Camera to pick/take photos. After they switch the default camera/picker app, this issue doesn't happen anymore. I don't know what to make of this. I guess the library should still handle this problem as we can't ask all our users to change their default apps, but don't really know the root cause in order to debug effectively. |
Ok, after doing a little reading it seems that this plugin is now archived and seeking a maintainer so I don't think we can expect a fix any time soon. Ref: #903 The recommendation is to migrate to Xamarin.Essentials MediaPicker however it is lacking some important features (and thus not a replacement for this plugin yet): xamarin/Essentials#1640 I also noticed that the comment here xamarin/Essentials#1410 (comment) mentions "On Android you just have to insert the EXTRA_ALLOW_MULTIPLE to the intent. However some apps like the Samsung Gallery ignore it". @nikadli I wonder if the two issues are related? It is interesting to note your observation though, thanks for that. And ... no, I won't be able to recommended to our user base to change their default camera/picker app lol. |
@RhomGit yup, I read somewhere in one of similar issues comments that this same issue still exists in Xamarin Essentials Media Picker 1.6. And like you said, it's not a replacement for this plugin yet. But if this issue is fixed there, eventually I think I will migrate to Xamarin Essentials anyway. That comment is interesting, most likely that's why only Samsung Gallery encounter this problem. Thanks to your clue about the intent, I found this - https://stackoverflow.com/questions/51780105/picking-multiple-images-on-clicking-from-gallery. Looks like there's a way to force insert that intent. Except it's not immediately clear how to do that in Xamarin Forms. Probably have to do this in platform-specific project. |
Also on this, they dont really have to change default. If the OS prompts to choose which apps to use, just don't choose Samsung apps. But this is less than ideal of course. |
public async void Agregar_Clicked(object sender, EventArgs e)
{
The text was updated successfully, but these errors were encountered: