[UWP] Random exception once per 15-20 times

Good morning,

i made custom toolbar controls that edit the image using SkiaSharp and load the edited image in the editor:

CODE:

        private void Slider_Threshold_DragCompleted(object sender, System.EventArgs e)
        {
            if (this.isLoadingImage)
                return;

            Slider slider = (Slider)sender;

            byte sliderValue = (byte)slider.Value;

            SKBitmap invertedBitmap = XXXImageProcessor.ThresholdFilter(this.thresholdTempSKBitmap, sliderValue);

            SKImage sKImage = SKImage.FromBitmap(invertedBitmap);

            SKData sKData = sKImage.Encode(SKEncodedImageFormat.Png, 100);

            this.LoadImage(ImageSource.FromStream(sKData.AsStream));
        }

        private void LoadImage(ImageSource imageSource)
        {
            this.isLoadingImage = true;

            this.sfImageEditor.Source = imageSource;
        }

90% of the times work perfectly, but randomly fires a XAML unhandled exception making the app to crash:

Exception thrown at 0x00007FF8A5CAD759 (KernelBase.dll) in XXX.UWP.exe: WinRT originate error - 0x80070057 : 'System.ArgumentException: The parameter is incorrect.

The control does not currently have a CanvasDevice associated with it. Ensure that resources are created from a CreateResources or Draw event handler.
   at Microsoft.Graphics.Canvas.CanvasBitmap.LoadAsync(ICanvasResourceCreator resourceCreator, IRandomAccessStream stream)
   at Syncfusion.UI.Xaml.ImageEditor.SfImageEditor.GetImageStream()
   at System.Threading.WinRTSynchronizationContextBase.Invoker.InvokeCore()'.
onecore\com\combase\winrt\error\restrictederror.cpp(1016)\combase.dll!00007FF8A743D0D3: (caller: 00007FF8A744B6B9) ReturnHr(6) tid(4d98) 8007007E The specified module could not be found.
Exception thrown at 0x00007FF8A5CAD759 (KernelBase.dll) in XXX.UWP.exe: WinRT originate error - 0x80070057 : 'The parameter is incorrect.

The control does not currently have a CanvasDevice associated with it. Ensure that resources are created from a CreateResources or Draw event handler.'.
onecore\com\combase\winrt\error\restrictederror.cpp(1016)\combase.dll!00007FF8A743D0D3: (caller: 00007FF8A744B6B9) ReturnHr(7) tid(4d98) 8007007E The specified module could not be found.


Platform: UWP x64

On Android and IOS works fine, just a problem with UWP.

Xamarin.Forms 4.7.0.1351

Syncfusion 18.3.0.40

Please it's urgent because we are in production.

Thanks in advance


3 Replies 1 reply marked as answer

ET Eswaran Thirugnanasambandam Syncfusion Team February 11, 2021 02:53 PM UTC

Hi Marco Negroni,  
 
Thanks for contacting Syncfusion support.  
 
We checked the reported issue based on your use case by adding the SKImage source to the image editor and we are unable to reproduce the issue from our side. Also, we don’t know image process type used in your code.  
 
SKBitmap invertedBitmap = XXXImageProcessor.ThresholdFilter(this.thresholdTempSKBitmap, sliderValue); 
 
Can you please share a simple sample that replicates the issue, and It will be helpful for us to check the reported issue and provide a faster solution. 
 
Regards, 
Eswaran 



MN Marco Negroni replied to Eswaran Thirugnanasambandam February 16, 2021 03:40 PM UTC

Hi Marco Negroni,  
 
Thanks for contacting Syncfusion support.  
 
We checked the reported issue based on your use case by adding the SKImage source to the image editor and we are unable to reproduce the issue from our side. Also, we don’t know image process type used in your code.  
 
SKBitmap invertedBitmap = XXXImageProcessor.ThresholdFilter(this.thresholdTempSKBitmap, sliderValue); 
 
Can you please share a simple sample that replicates the issue, and It will be helpful for us to check the reported issue and provide a faster solution. 
 
Regards, 
Eswaran 


Good morning,

i made an example for you, you need to load multiple images in the editor, fast; because for example to invert colors, we need to get the image from the editor, invert colors and load again in the editor.

In the following example i just load 50 times an image and you will see the imageeditor crash under UWP.


Sometime you will get the following exception:

The image header is unrecognized. (Exception from HRESULT: 0x88982F61)

Sometime you will get the following exception:

The parameter is incorrect.

The control does not currently have a CanvasDevice associated with it. Ensure that resources are created from a CreateResources or Draw event handler.


In the real software we are getting the image from the editor using the following code:

                        Stream imageStream = null;

                        try
                        {
                            imageStream = await this.sfImageEditor.GetStream();
                        }
                        catch
                        {
                            return;
                        }

Then we edit the image and we load the image with the following code:

this.sfImageEditor.Source = imageSource;

The images are fine, we checked them, is just a problem loading them sequentially in the editor.

Please it's urgent.

Thanks very much

PS: if you need i'll provide a more accurate example.




SS Sridevi Sivakumar Syncfusion Team February 17, 2021 04:35 PM UTC

Hi Marco Negroni,

Thanks for sharing the information.

We have checked the reported query with a shared sample, and random issue occurred when continuously update the image editor source. You could resolve this can resolve this problem by updating source with little delay as per the below code snippet,

       private async void Button_Clicked(object sender, EventArgs e)

        {

            imageLoaded = false;

 

            for (int i = 0; i < 100; i++)

            {

                if (!imageLoaded)

                {

                    this.imageEditor.Source = ImageSource.FromResource("IESample.Image.jpeg", this.assembly);

                   await Task.Delay(150);

                }

            }

        }


As your app similar like this this scenario, please try above approach to resolve the issue.

Please let us know if you need any further assistance.

Regards, 
Sridevi S.

 


Marked as answer
Loader.
Up arrow icon