#677 ✓ resolved
brianchirls

Javascript error in main update code if a plugin removes itself

Reported by brianchirls | August 3rd, 2011 @ 03:08 PM | in 1.0 Release (closed)

In the unit test "Update Timer" (under module "Popcorn Plugin"), the final .exec calls plus(), which removes exec. By the time everything returns back to the main loop, the exec event has removed itself.

The following code uses my new animation stuff (but not Rick's registry check).


              while ( tracksByStart[ tracks.startIndex ] && tracksByStart[ tracks.startIndex ].start <= currentTime ) {
                //  If plugin does not exist on this instance, remove it
                if ( !tracksByStart[ tracks.startIndex ]._natives || !!that[ tracksByStart[ tracks.startIndex ]._natives.type ] ) {
                  if ( tracksByStart[ tracks.startIndex ].end > currentTime &&
                        tracksByStart[ tracks.startIndex ]._running === false &&
                          that.data.disabled.indexOf( tracksByStart[ tracks.startIndex ]._natives.type ) === -1 ) {
var lastTrackEventCalled = tracksByStart[ tracks.startIndex ];
                    tracksByStart[ tracks.startIndex ]._running = true;
                    tracksByStart[ tracks.startIndex ]._natives.start.call( that, event, tracksByStart[ tracks.startIndex ] );
//*** after exec runs, tracks.startIndex is wrong. and Javascript error happens here
//"Cannot read property '_natives' of undefined"
                    if (tracksByStart[ tracks.startIndex ]._natives.frame) {
                      tracksAnimating.push(tracksByStart[ tracks.startIndex ]);
                    }
                  }
                  tracks.startIndex++;
                } else {
                  // remove track event
                  Popcorn.removeTrackEvent( that, tracksByStart[ tracks.startIndex ]._id );
                  return;
                }
              }

Why don't we set a variable at the beginning of the loop to hold tracksByStart[ tracks.startIndex ] anyway?

We may also have to run some more thorough checks on startIndex and endIndex - I'm not sure what else this could be screwing up.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Popcorn.js is an HTML5 video framework that lets you bring elements of the web into your videos.

Popcorn.js is a project of Web Made Movies, Mozilla's Open Video Lab.

Shared Ticket Bins

Pages