Browse Source

fix for project unloaded event to account for services de-registering themselves during the loop

Shaddock Heath 9 years ago
parent
commit
7a43a8fe60
1 changed files with 3 additions and 3 deletions
  1. 3 3
      Script/AtomicEditor/hostExtensions/HostExtensionServices.ts

+ 3 - 3
Script/AtomicEditor/hostExtensions/HostExtensionServices.ts

@@ -77,8 +77,8 @@ export class ProjectServiceRegistry extends ServiceRegistry<Editor.HostExtension
      * @param  {[type]} data Event info from the project unloaded event
      */
     projectUnloaded(data) {
-        // Need to use a for loop and don't cache the length because the list of services *may* change while processing
-        for (let i = 0; i < this.registeredServices.length; i++) {
+        // Need to use a for loop for length down to 0 because extensions *could* delete themselves from the list on projectUnloaded
+        for (let i = this.registeredServices.length - 1; i >= 0; i--) {
             let service = this.registeredServices[i];
             // Notify services that the project has been unloaded
             try {
@@ -96,7 +96,7 @@ export class ProjectServiceRegistry extends ServiceRegistry<Editor.HostExtension
      * @param  {[type]} data Event info from the project unloaded event
      */
     projectLoaded(ev: Editor.EditorEvents.LoadProjectEvent) {
-        // Need to use a for loop and don't cache the length because the list of services *may* change while processing
+        // Need to use a for loop and don't cache the length because the list of services *may* change while processing.  Extensions could be appended to the end
         for (let i = 0; i < this.registeredServices.length; i++) {
             let service = this.registeredServices[i];
             try {