public static void Close() { OnGraphPreScan = null; OnGraphPostScan = null; OnPreScan = null; OnPostScan = null; OnLatePostScan = null; OnGraphsUpdated = null; }
/** Clears up variables and other stuff, destroys graphs. * Note that when destroying an AstarPath object, all static variables such as callbacks will be cleared. */ public void OnDestroy () { if (logPathResults == PathLog.Heavy) Debug.Log ("+++ AstarPath Component Destroyed - Cleaning Up Pathfinding Data +++"); if ( active != this ) return; //Don't accept any more path calls to this AstarPath instance. //This will cause all eventual multithreading threads to exit pathQueue.TerminateReceivers(); BlockUntilPathQueueBlocked(); FlushWorkItems (); if (logPathResults == PathLog.Heavy) Debug.Log ("Processing Eventual Work Items"); // Process work items until done // Nope, don't do this //PerformBlockingActions (true); //Resume graph update thread, will cause it to terminate graphUpdateAsyncEvent.Set(); //Try to join pathfinding threads if (threads != null) { for (int i=0;i<threads.Length;i++) { #if UNITY_WEBPLAYER if (!threads[i].Join(200)) { Debug.LogError ("Could not terminate pathfinding thread["+i+"] in 200ms." + "Not good.\nUnity webplayer does not support Thread.Abort\nHoping that it will be terminated by Unity WebPlayer"); } #else if (!threads[i].Join (50)) { Debug.LogError ("Could not terminate pathfinding thread["+i+"] in 50ms, trying Thread.Abort"); threads[i].Abort (); } #endif } } if (logPathResults == PathLog.Heavy) Debug.Log ("Returning Paths"); //Return all paths ReturnPaths (false); //Just in case someone happened to request a path in ReturnPath() (even though they should get canceled) pathReturnStack.PopAll (); if (logPathResults == PathLog.Heavy) Debug.Log ("Destroying Graphs"); //Clean graphs up astarData.OnDestroy (); if (logPathResults == PathLog.Heavy) Debug.Log ("Cleaning up variables"); //Clear variables up, static variables are good to clean up, otherwise the next scene might get weird data floodStack = null; graphUpdateQueue = null; //Clear all callbacks OnDrawGizmosCallback = null; OnAwakeSettings = null; OnGraphPreScan = null; OnGraphPostScan = null; OnPathPreSearch = null; OnPathPostSearch = null; OnPreScan = null; OnPostScan = null; OnLatePostScan = null; On65KOverflow = null; OnGraphsUpdated = null; OnSafeCallback = null; OnThreadSafeCallback = null; threads = null; threadInfos = null; PathsCompleted = 0; active = null; }
/** Clears up variables and other stuff, destroys graphs. * Note that when destroying an AstarPath object, all static variables such as callbacks will be cleared. */ public void OnDestroy () { if (logPathResults == PathLog.Heavy) Debug.Log ("+++ AstarPath Component Destroyed - Cleaning Up Pathfinding Data +++"); //Don't accept any more path calls to this AstarPath instance. //This will cause all eventual multithreading threads to exit TrickAbortThreads (); //Try to join pathfinding threads if (threads != null) { for (int i=0;i<threads.Length;i++) { #if UNITY_WEBPLAYER if (!threads[i].Join(200)) { Debug.LogError ("Could not terminate pathfinding thread["+i+"] in 200ms." + "Not good.\nUnity webplayer does not support Thread.Abort\nHoping that it will be terminated by Unity WebPlayer"); } #else if (!threads[i].Join (50)) { Debug.LogError ("Could not terminate pathfinding thread["+i+"] in 50ms, trying Thread.Abort"); threads[i].Abort (); } #endif } } if (logPathResults == PathLog.Heavy) Debug.Log ("Destroying Graphs"); //Clean graphs up if (astarData.graphs != null) { for (int i=0;i<astarData.graphs.Length;i++) { astarData.graphs[i].OnDestroy (); } } astarData.graphs = null; if (logPathResults == PathLog.Heavy) Debug.Log ("Returning Paths"); //Return all paths with errors /*Path p = pathReturnStack.PopAll (); while (p != null) { p.Error (); p.LogError ("Canceled because AstarPath object was destroyed\n"); p.AdvanceState (PathState.Returned); p.ReturnPath (); Path tmp = p; p = p.next; tmp.next = null; }*/ ReturnPaths (false); //Just in case someone happened to request a path in ReturnPath() (even though they should get canceled) pathReturnStack.PopAll (); if (logPathResults == PathLog.Heavy) Debug.Log ("Cleaning up variables"); //Clear variables up, static variables are good to clean up, otherwise the next scene might get weird data floodStack = null; graphUpdateQueue = null; //Clear all callbacks OnDrawGizmosCallback = null; OnAwakeSettings = null; OnGraphPreScan = null; OnGraphPostScan = null; OnPathPreSearch = null; OnPathPostSearch = null; OnPreScan = null; OnPostScan = null; OnLatePostScan = null; On65KOverflow = null; OnGraphsUpdated = null; OnSafeCallback = null; OnThreadSafeCallback = null; pathQueue.Clear (); threads = null; threadInfos = null; numActiveThreads = 0; ResetQueueStates (); PathsCompleted = 0; active = null; }
/// <summary> /// Clears up variables and other stuff, destroys graphs. /// Note that when destroying an AstarPath object, all static variables such as callbacks will be cleared. /// </summary> void OnDestroy() { // This class uses the [ExecuteInEditMode] attribute // So OnDestroy is called even when not playing // Don't do anything when not in play mode if (!Application.isPlaying) { return; } if (logPathResults == PathLog.Heavy) { Debug.Log("+++ AstarPath Component Destroyed - Cleaning Up Pathfinding Data +++"); } if (active != this) { return; } // Block until the pathfinding threads have // completed their current path calculation PausePathfinding(); navmeshUpdates.OnDisable(); euclideanEmbedding.dirty = false; FlushWorkItems(); // Don't accept any more path calls to this AstarPath instance. // This will cause all pathfinding threads to exit (if any exist) pathProcessor.queue.TerminateReceivers(); if (logPathResults == PathLog.Heavy) { Debug.Log("Processing Possible Work Items"); } // Stop the graph update thread (if it is running) graphUpdates.DisableMultithreading(); // Try to join pathfinding threads pathProcessor.JoinThreads(); if (logPathResults == PathLog.Heavy) { Debug.Log("Returning Paths"); } // Return all paths pathReturnQueue.ReturnPaths(false); if (logPathResults == PathLog.Heavy) { Debug.Log("Destroying Graphs"); } // Clean up graph data data.OnDestroy(); if (logPathResults == PathLog.Heavy) { Debug.Log("Cleaning up variables"); } // Clear variables up, static variables are good to clean up, otherwise the next scene might get weird data // Clear all callbacks OnAwakeSettings = null; OnGraphPreScan = null; OnGraphPostScan = null; OnPathPreSearch = null; OnPathPostSearch = null; OnPreScan = null; OnPostScan = null; OnLatePostScan = null; On65KOverflow = null; OnGraphsUpdated = null; active = null; }
/** Clears up variables and other stuff, destroys graphs */ public void OnDestroy () { if (logPathResults == PathLog.Heavy) Debug.Log ("+++ Destroyed - Cleaning Up Pathfinding Data +++"); //Don't accept any more path calls to this AstarPath instance. This will also cause the eventual multithreading thread to abort acceptNewPaths = false; //Stop the multithreading thread if (activeThread != null) { if (!activeThread.Join (100)) { Debug.LogError ("Could not terminate pathfinding thread properly, trying Thread.Abort"); activeThread.Abort (); } activeThread = null; } //Must be set before the OnDestroy calls are made, since they might call RegisterSafeNodeUpdate, and if it set to true then the callback will never be called isCalculatingPaths = false; if (logPathResults == PathLog.Heavy) Debug.Log ("Destroying Graphs"); //Clear graphs up if (astarData.graphs != null) { for (int i=0;i<astarData.graphs.Length;i++) { astarData.graphs[i].OnDestroy (); } } astarData.graphs = null; if (logPathResults == PathLog.Heavy) Debug.Log ("Returning Paths"); //Return all paths with errors if (useMultithreading) { while (pathReturnQueueStart != null) { Path p = pathReturnQueueStart; p.error = true; p.errorLog = "Canceled because AstarPath object was destroyed"; p.ReturnPath (); if (p.next != null) { pathReturnQueueStart = p.next; } else { break; } } } else { while (pathQueueStart != null) { Path p = pathQueueStart; p.error = true; p.errorLog = "Canceled because AstarPath object was destroyed"; p.ReturnPath (); if (p.next != null) { pathQueueStart = p.next; } else { break; } } } if (pathQueueStart != null) { pathQueueStart.next = null; pathQueueStart.error = true; pathQueueStart.callback = null; } if (logPathResults == PathLog.Heavy) Debug.Log ("Cleaning up variables"); //Clear variables up, static variables are good to clean up, otherwise the next scene might get weird data floodStack = null; graphUpdateQueue = null; //astarData = null; binaryHeap = null; pathQueueEnd = null; pathQueueStart = null; pathReturnQueueStart = null; missedPathQueueIncrement = false; OnGraphPreScan = null; OnGraphPostScan = null; OnPathPreSearch = null; OnPathPostSearch = null; OnPreScan = null; OnPostScan = null; OnGraphUpdate = null; OnGraphsUpdated = null; PathsCompleted = 0; //isActiveSet = false; active = null; }