Clean up dispose pattern, remove sentence fragment

This commit is contained in:
Steve Hawley 2022-01-21 10:03:49 -05:00
Родитель ef5475c172
Коммит 25d3e11305
7 изменённых файлов: 33 добавлений и 42 удалений

Просмотреть файл

@ -124,7 +124,7 @@ The Swift code uses five files to organize the behavior of the single class `Vie
I occasionally refactored the Swift code where I thought it helped legibility or reduced repetition. Usually this was in the form of extracting a function.
One area where there is considerably variance from the Swift code is in the "Utility_Extensions" folder. Xamarin.iOS uses OpenTK vector and matrix classes for manipulating 3D objects and transforms. The OpenTK classes have different APIs and
One area where there is considerably variance from the Swift code is in the "Utility_Extensions" folder. Xamarin.iOS uses OpenTK vector and matrix classes for manipulating 3D objects and transforms.
A matter of internal debate was the clearest form for porting Swift `guard` statements that assign a local variable if the passed-in variable is not `null`. The options are:

Просмотреть файл

@ -801,26 +801,16 @@ internal class BoundingBox : SCNNode
// Dispose pattern for debugging purposes
bool disposed = false;
internal bool IsDisposed
{
get
{
return disposed;
}
}
internal bool IsDisposed => disposed;
override protected void Dispose (bool disposing)
{
if (!disposed)
{
disposed = true;
if (disposing)
{
base.Dispose ();
}
NSNotificationCenter.DefaultCenter.RemoveObserver (notificationObserverHandle);
}
base.Dispose (disposing);
}
internal new void Dispose ()

Просмотреть файл

@ -515,13 +515,9 @@ internal class ObjectOrigin : SCNNode
{
disposed = true;
if (disposing)
{
base.Dispose ();
}
NSNotificationCenter.DefaultCenter.RemoveObserver (notificationObserverHandles [0]);
NSNotificationCenter.DefaultCenter.RemoveObserver (notificationObserverHandles [1]);
}
base.Dispose (disposing);
}
}

Просмотреть файл

@ -341,16 +341,12 @@ internal class ScannedObject : SCNNode
if (!disposed)
{
disposed = true;
if (disposing)
{
base.Dispose ();
}
NSNotificationCenter.DefaultCenter.RemoveObserver (notificationObserverHandle);
Origin?.Dispose ();
BoundingBox?.Dispose ();
GhostBoundingBox?.Dispose ();
}
base.Dispose (disposing);
}
#endregion

Просмотреть файл

@ -142,15 +142,11 @@ internal class ScannedPointCloud : SCNNode
if (!disposed)
{
disposed = true;
if (disposing)
{
base.Dispose ();
}
foreach (var notificationObserverHandle in notificationObservationHandles)
{
NSNotificationCenter.DefaultCenter.RemoveObserver (notificationObserverHandle);
}
}
base.Dispose (disposing);
}
}

Просмотреть файл

@ -152,6 +152,7 @@ Do you want to go back and adjust the bounding box of the scanned object?""";
sceneView.Scene.RootNode.AddChildNode (pointCloud);
}
bool disposed;
internal new void Dispose ()
{
Dispose (true);
@ -160,14 +161,19 @@ Do you want to go back and adjust the bounding box of the scanned object?""";
protected override void Dispose (bool disposing)
{
if (disposing)
if (!disposed)
{
scannedObject?.RemoveFromParentNode ();
pointCloud?.RemoveFromParentNode ();
disposed = true;
if (disposing)
{
scannedObject?.RemoveFromParentNode ();
pointCloud?.RemoveFromParentNode ();
scannedObject?.Dispose ();
pointCloud?.Dispose ();
scannedObject?.Dispose ();
pointCloud?.Dispose ();
}
}
base.Dispose (disposing);
}
void ApplicationStateChanged (NSNotification notification)

Просмотреть файл

@ -115,6 +115,8 @@ internal class TestRun : NSObject, IDisposable
noDetectionTimer = null;
}
bool disposed;
internal new void Dispose ()
{
Dispose (true);
@ -123,18 +125,23 @@ internal class TestRun : NSObject, IDisposable
protected override void Dispose (bool disposing)
{
if (disposing)
if (!disposed)
{
DetectedObject?.RemoveFromParentNode ();
if (sceneView.Session.Configuration as ARWorldTrackingConfiguration is not null)
disposed = true;
if (disposing)
{
// Make sure we switch back to an object scanning configuration & no longer
// try to detect the object.
var configuration = new ARObjectScanningConfiguration ();
configuration.PlaneDetection = ARPlaneDetection.Horizontal;
sceneView.Session.Run (configuration, ARSessionRunOptions.ResetTracking);
DetectedObject?.RemoveFromParentNode ();
if (sceneView.Session.Configuration as ARWorldTrackingConfiguration is not null)
{
// Make sure we switch back to an object scanning configuration & no longer
// try to detect the object.
var configuration = new ARObjectScanningConfiguration ();
configuration.PlaneDetection = ARPlaneDetection.Horizontal;
sceneView.Session.Run (configuration, ARSessionRunOptions.ResetTracking);
}
}
base.Dispose (disposing);
}
}
}