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

iOS app when opening the camera to take a photo and displaying the crop popup and closing the popup the second time crashes #13

Open
ntbao17 opened this issue May 3, 2024 · 5 comments

Comments

@ntbao17
Copy link

ntbao17 commented May 3, 2024

*** Terminating app due to uncaught exception 'System.ObjectDisposedException', reason: 'Cannot access a disposed object.
Object name: 'RGPopup.Maui.IOS.Platform.PopupWindow'. (System.ObjectDisposedException)
at ObjCRuntime.ThrowHelper.ThrowObjectDisposedException(Object o) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/ThrowHelper.cs:line 52
at Foundation.NSObject.get_SuperHandle() in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:line 615
at UIKit.UIWindow.get_RootViewController() in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/dotnet/ios/generated-sources/UIKit/UIWindow.g.cs:line 385
at BigTed.ProgressHUD.RemoveHud()
at Foundation.NSActionDispatcher.Apply() in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSAction.cs:line 61
at Foundation.NSObject.InvokeOnMainThread(Action action) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:line 782
at BigTed.ProgressHUD.b__145_1()
at UIKit.UIView.<>c__DisplayClass12_0.b__0(Boolean x) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIView.cs:line 124
at ObjCRuntime.Trampolines.SDUICompletionHandler.Invoke(IntPtr block, Byte finished) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/dotnet/ios/generated-sources/ObjCRuntime/Trampolines.g.cs:line 45753
at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 58
at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 94
at ClubSync.Program.Main(String[] args) in /Users/admin/Projects/GitTea/ClubSyncMobile/Clubsync/Platforms/iOS/Program.cs:line 13
'
*** First throw call stack:

@microspaze
Copy link
Owner

@ntbao17 Which version did you tested? I have tested the latest version 1.0.8 with the RGPopup.Samples on my own device. It seems work for me. Can you provide more detail about this issue, same code snips or a demo project? Thanks.

@ntbao17
Copy link
Author

ntbao17 commented May 3, 2024

RGPopup.Maui-main.zip

I use version 1.0.8, I send you a demo in which there is an error when using vs popup => MauiContext should have been set on parent to use. As for using vs page, I usually only try it on iOS. Please help me see, thank you very much!

@microspaze
Copy link
Owner

microspaze commented May 3, 2024

After testing the demo project you uploaded, there are two incorrect points in your code.

  1. For test case 1, the way you popup the PageCropImage is not right.
//Case 1
var pagecrop = new Pages.PageCropImage(sourceStream);
pagecrop.OnCropImageComplete += (r) =>
{
    Navigation.PopAsync();
};
await Navigation.PushAsync(pagecrop);

Navigation.PushAsync and Navigation.PopAsync are MAUI framework's methods. They pop new page to the system navigation stack, but not to current page window. The right methods should be Navigation.PushPopupAsync and Navigation.PopPopupAsync (Or you can use PopupNavigation.Instance to replace Navigation to call PushAsync and PopAsync). And PageCropImage should extends from PopupPage but not from ContentPage. Like:

public partial class PageCropImage : PopupPage

var pagecrop = new Pages.PageCropImage(sourceStream);
pagecrop.OnCropImageComplete += async (r) =>
{
    await Navigation.PopPopupAsync();
};
await Navigation.PushPopupAsync(pagecrop);

  1. For test case 2, the Syncfusion.Maui.ImageEditor seems not support to work in a dynamic set content view. PopupHelper.ShowPopup will generate a BasePopupPage and replace its content by the content view you gaven dynamically. From the debug error, it crashed when calling Syncfusion.Maui.ImageEditor.ImageEditLayout.SaveCrop() method from var stream = await ImageEditor.GetImageStream();. Here is the full stacktrace:
   at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view)
   at Microsoft.Maui.Handlers.LayoutHandler.Remove(IView child)
   at Microsoft.Maui.Handlers.LayoutHandler.MapRemove(ILayoutHandler handler, ILayout layout, Object arg)
   at Microsoft.Maui.CommandMapper`2.<>c__DisplayClass6_0[[Microsoft.Maui.ILayout, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.ILayoutHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v, Object o)
   at Microsoft.Maui.CommandMapper.InvokeCore(String key, IElementHandler viewHandler, IElement virtualView, Object args)
   at Microsoft.Maui.CommandMapper.Invoke(IElementHandler viewHandler, IElement virtualView, String property, Object args)
   at Microsoft.Maui.Handlers.ElementHandler.Invoke(String command, Object args)
   at Microsoft.Maui.Controls.Layout.NotifyHandler(String action, Int32 index, IView view)
   at Microsoft.Maui.Controls.Layout.OnRemove(Int32 index, IView view)
   at Microsoft.Maui.Controls.Layout.RemoveAt(Int32 index)
   at Microsoft.Maui.Controls.Layout.Remove(IView child)
   at Syncfusion.Maui.ImageEditor.ImageEditLayout.RemoveCropView()
   at Syncfusion.Maui.ImageEditor.ImageEditLayout.SaveCrop()
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
   at Foundation.NSAsyncSynchronizationContextDispatcher.Apply() in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSAction.cs:line 176
   at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 58
   at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 94
   at RGPopup.Samples.Program.Main(String[] args) in /Users/zmark/Downloads/RGPopup.Maui-main/RGPopup.Samples/Platforms/iOS/Program.cs:line 13

I think it may be a unsupport issue in Syncfusion.Maui.ImageEditor but not in RGPopup.Maui.

After correcting the case 1 code, it works fine for me.

@ntbao17
Copy link
Author

ntbao17 commented May 3, 2024

In case 1, I use pagecontent to demonstrate that ImageEditor.GetImageStream() works well.
In case 2, when using popup from RGPopup.Maui, the error is as you sent above.
Please help me see, thank you very much!

@microspaze
Copy link
Owner

PopupHelper.ShowPopup is not the recommend way to pop PopupPage content. As I said, it may not be supportted by MAUI framework or Syncfusion.Maui.ImageEditor. The reccomend way is to make PageCropImage inherit from PopupPage. And then just popup the PageCropImage.

public partial class PageCropImage : PopupPage
.....

//Case 1
var pagecrop = new Pages.PageCropImage(sourceStream);
pagecrop.OnCropImageComplete += async (r) =>
{
    await Navigation.PopPopupAsync();
};
await Navigation.PushPopupAsync(pagecrop);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants