Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Added locking around the disposal of the observer
Browse files Browse the repository at this point in the history
  • Loading branch information
bijington committed Sep 22, 2022
1 parent d87341a commit f532b9f
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/Media.Plugin/iOS/MediaPickerDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public void DisplayPopover(bool hideFirst = false)

UIDeviceOrientation? orientation;
NSObject observer;
readonly object observerDisposeLock = new object();
readonly UIViewController viewController;
readonly UIImagePickerControllerSourceType source;
TaskCompletionSource<List<MediaFile>> tcs = new TaskCompletionSource<List<MediaFile>>();
Expand Down Expand Up @@ -203,18 +204,24 @@ void RemoveOrientationChangeObserverAndNotifications()

if (observer != null)
{
try
{
NSNotificationCenter.DefaultCenter.RemoveObserver(observer);
}
catch (Exception ex)
lock (observerDisposeLock)
{
Debug.WriteLine(ex);
}
if (observer != null)
{
try
{
NSNotificationCenter.DefaultCenter.RemoveObserver(observer);
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}

observer.Dispose();
observer = null;
}
}
}
observer?.Dispose();
observer = null;
}

void DidRotate(NSNotification notice)
Expand Down

0 comments on commit f532b9f

Please sign in to comment.