Image Editor crashes with editor.Save(".png")

Dear Team,

I had the necessity to add multiple buttons to save the edited image, with each button doing different action after saving. With no specific behavior, the editor.Save() crashes giving the exceptions you will find at the end of the message. It seems like it happens when initializing for the second time the Page with the editor in it, but it happens too at the first or third time. I'm trying to recreate an example project to replicate the error to let you try it and see what happens, I'll upload it whenever I manage to replicate the error.

Platform: UWP (didn't try on Android or iOS)
SfImageEditor version: 17.4.0.47 (updating to 19.1.0.59 didn't resolve the issue)
The project is Master Page based, with navigation between pages. The editor is inside a page that appears when clicking on a button. 

----------------------------------------------------------------
SfImageEditor.Save (String format, Size size)
System.NullReferenceException: Object reference not set to an instance of an object.
Syncfusion.UI.Xaml.ImageEditor SfImageEditor.Save (String format, Size size)
Syncfusion.SfImageEditor.XForms.UWP ImageEditorDependencyServiceMapping.Save (Object obj, String format, Size size)
Syncfusion.SfImageEditor.XForms SfImageEditor.Save (String format, Size size)
AuditManager.Views AddPhotoPage.<OnAppearing>b__14_1 (AddPhotoViewModel sender)
System RuntimeMethodHandle.InvokeMethod (Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
System.Reflection RuntimeMethodInfo.Invoke (Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
Xamarin.Forms.MessagingCenter Subscription.InvokeCallback (Object sender, Object args)
Xamarin.Forms MessagingCenter.InnerSend (String message, Type senderType, Type argType, Object sender, Object args)
Xamarin.Forms.MessagingCenter.Xamarin.Forms IMessagingCenter.Send[TSender] (TSender sender, String message)
Xamarin.Forms MessagingCenter.Send[TSender] (TSender sender, String message)
AuditManager.ViewModels AddPhotoViewModel.ExecuteAddSameAttachmentCommand ()
AuditManager.ViewModels AddPhotoViewModel.<ctor>b__72_3 ()
Xamarin.Forms.Command <>c__DisplayClass4_0.<ctor>b__0 (Object o)
Xamarin.Forms Command.Execute (Object parameter)
Xamarin.Forms.MenuItem.Xamarin.Forms IMenuItemController.Activate ()
Xamarin.Forms.Platform.UWP MenuItemCommand.Execute (Object parameter)
System.Runtime.InteropServices.WindowsRuntime ICommandToWinRTAdapter.Execute (Object parameter)
Windows.ApplicationModel.Core UnhandledError.Propagate ()
Microsoft.AppCenter.Utils ApplicationLifecycleHelper.<ctor>b__17_1 (Object sender, UnhandledErrorDetectedEventArgs eventArgs)
----------------------------------------------------------------
BitmapExtension.GetImageSource (FrameworkElement targetElement, Int32 pixelWidth, Int32 pixelHeight, Int32 angle, Boolean isFlipped, Double scale)
System.NullReferenceException: Object reference not set to an instance of an object.
Syncfusion.UI.Xaml.ImageEditor BitmapExtension.GetImageSource (FrameworkElement targetElement, Int32 pixelWidth, Int32 pixelHeight, Int32 angle, Boolean isFlipped, Double scale)
Syncfusion.UI.Xaml.ImageEditor BitmapExtension.GetBitmapFromShapeView (FrameworkElement targetElement, Int32 pixelWidth, Int32 pixelHeight, Int32 angle, Boolean isFlipped, Double scale)
Syncfusion.UI.Xaml.ImageEditor SfImageEditor.getMergedBitmap (Boolean isfilterApplied)
Syncfusion.UI.Xaml.ImageEditor SfImageEditor.getCurrentStream ()
Syncfusion.UI.Xaml.ImageEditor SfImageEditor.SaveImage (String format, Size size)
System.Runtime.CompilerServices.AsyncMethodBuilderCore <>c.<ThrowAsync>b__7_0 (Object state)
System.Threading.WinRTSynchronizationContextBase Invoker.InvokeCore ()
Windows.ApplicationModel.Core UnhandledError.Propagate ()
Microsoft.AppCenter.Utils ApplicationLifecycleHelper.<ctor>b__17_1 (Object sender, UnhandledErrorDetectedEventArgs eventArgs)

5 Replies 1 reply marked as answer

SS Sridevi Sivakumar Syncfusion Team May 13, 2021 01:39 PM UTC

Hi DANILO LONGONI,

Greetings from Syncfusion.

We have prepared a sample to replicate the issue based on the provided details, but we are afraid, that we are not able to reproduce the issue at our end. The sample we tried can be downloaded from the below location.

Sample link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/SampleEditor1515894629

Since we are not aware of your exact application scenario, we were not able to reproduce this at our end, can you please revert us by modifying the sample based on your application along with the replication procedure.

Regards,
Sridevi S. 
 



DL DANILO LONGONI May 14, 2021 07:10 AM UTC

Hi Sridevi,

thank you for your help. I've downloaded the sample you provided and, as you said, it works correctly. But i managed to recreate the same behavior on your sample and make it crash while saving an image.
I made a simple edit to your code inside Page1.xaml.cs:
private async void Button_Clicked(object sender, EventArgs e)
{
editor.Save();
await Navigation.PopAsync();
}

The steps to reproduce the crash:
- Click the GoToEdit button
- Edit the photo (draw a line or add a shape)
- Click the save button (top left one)
- App should return to the Welcome page

When the app returns to the Welcome page it crashes, only if the image has been edited. 
I've attached the sample with the new line of code.

Regards


Attachment: SampleEditor1515894629_crash_90b284d2.zip


ET Eswaran Thirugnanasambandam Syncfusion Team May 17, 2021 11:36 AM UTC

Hi DANILO LONGONI, 
 
Thanks for your update. 
 
We have checked the reported issue” App crashes when saving the image”. The issue occurs due to triggering image editor saving and page dispose action in same time. So, In image editor saving method, we got SfImageeditor object as null due to dispose.  
 
You can resolve this problem by calling page dispose in minimum delay as per the below code snippet. 
 
Code snippet:  
 
private async void Button_Clicked(object sender, EventArgs e)  
        {  
            editor.Save();  
            await Task.Delay(100);  
            await Navigation.PopAsync();  
       
  
We have modified your sample based on this, please find the sample from the following location. 
 
 
Please check the sample and let us know if you have any other concerns. 
 
Regards, 
Eswaran. 


Marked as answer

DL DANILO LONGONI May 19, 2021 03:03 PM UTC

Dear Eswaran,

sorry for the inconvenience, the main problem was a subscribed message that wasn't unsubscribed during the OnDisappearing, multiple subscription obviously caused this problem.

Regards


SS Sridevi Sivakumar Syncfusion Team May 20, 2021 02:26 PM UTC

Hi DANILO LONGONI,

Have you resolved your problem by unsubscribing (Unhook) the events in the OnDisappearing method?

Or

If you still facing the problem with SfImageEditor, please share the subscribed related code snippet or code files or modified sample with us. This will be helpful for us to provide you better solution at the earliest.

Regards,
Sridevi S.
 


Loader.
Up arrow icon