Steema Issues Database

Note: This database is for bugs and wishes only. For technical support help, if you are a customer please visit our online forums;
otherwise you can use StackOverflow.
Before using this bug-tracker we recommend a look at this document, Steema Bug Fixing Policy.



Bug 2188 - ObjectDisposedException: Cannot access a disposed object
Summary: ObjectDisposedException: Cannot access a disposed object
Status: RESOLVED FIXED
Alias: None
Product: .NET TeeChart
Classification: Unclassified
Component: iOS (show other bugs)
Version: unspecified
Hardware: Phone iOS
: Highest blocker
Target Milestone: ---
Assignee: Steema Issue Manager
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-04-25 12:03 EDT by Bill
Modified: 2019-04-26 04:07 EDT (History)
2 users (show)

See Also:
Chart Series: ---
Delphi / C++ Builder RAD IDE Version:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bill 2019-04-25 12:03:40 EDT
after I upgrade "TeeChart for Xamarin.Forms 2018 4.2018.05.16" to "TeeChart for Xamarin Forms 2018 4.2018.09.19".
I saw this chanages:
public virtual void DoInvalidate()
{
+    DispatchQueue.GetGlobalQueue(DispatchQueuePriority.High).DispatchAsync(() => DispatchQueue.MainQueue.DispatchAsync(() => this.SetNeedsDisplay()));
    this.SetNeedsDisplay();
}

I don't know why use DispatchAsync() to call SetNeedsDisplay().
when callback from MainQueue, "this" object maybe already disposed.
thus it cause exception in MainThread, and crash the app.

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'TChartExt'.
  at Foundation.NSObject.get_SuperHandle () [0x00012] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.12/src/Xamarin.iOS/Foundation/NSObject2.cs:449 
  at UIKit.UIView.SetNeedsDisplay () [0x00023] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.12/src/Xamarin.iOS/UIKit/UIView.g.cs:1722 
  at Steema.TeeChart.TChart.<DoInvalidate>b__145_1 () [0x00000] in <6bf3489dbb0b46c8960fae68f948879a>:0 
  at CoreFoundation.DispatchQueue.static_dispatcher_to_managed (System.IntPtr context) [0x00038] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.12/src/Xamarin.iOS/CoreFoundation/Dispatch.cs:344 
  at (wrapper native-to-managed) CoreFoundation.DispatchQueue.static_dispatcher_to_managed(intptr)
  at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.12/src/Xamarin.iOS/UIKit/UIApplication.cs:79 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.12/src/Xamarin.iOS/UIKit/UIApplication.cs:63 
  at iOS.Application.Main (System.String[] args) [0x00002] in G:\Projects\Demo\iOS\Main.cs:20 

so:
1. why DispatchAsync() twice to call SetNeedsDisplay()?
2. if that is required for some reason, at least we use check "this" is not disposed before call SetNeedDisplay(),
such as: if (Handle != IntPtr.Zero) SetNeedsDisplay();
Comment 1 Bill 2019-04-25 12:20:55 EDT
or how about this:

        public override void DoInvalidate()
        {
            Action action = () =>
            {
                if (Handle != IntPtr.Zero)
                {
                    SetNeedsDisplay();
                }
            };

            if (NSThread.Current.IsMainThread)
            {
                action();
            }
            else
            {
                NSRunLoop.Main.BeginInvokeOnMainThread(action);
            }
        }
Comment 2 Bill 2019-04-25 13:25:15 EDT
it seems 4.2018.10.17 fixed that issue.

https://www.nuget.org/packages/Steema.TeeChart.NET.Xamarin.Forms/4.2018.10.17
Comment 3 Bill 2019-04-26 04:07:00 EDT
already fixed in newer version.