Skip to content
This repository has been archived by the owner on Jun 29, 2018. It is now read-only.

[#1317] Fixed issue where trackevents were not being removed properly wh... #192

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions popcorn.js
Original file line number Diff line number Diff line change
Expand Up @@ -1821,45 +1821,40 @@
var byStart = obj.data.trackEvents.byStart,
byEnd = obj.data.trackEvents.byEnd,
animating = obj.data.trackEvents.animating,
idx, sl;
sl;

// remove all trackEvents
for ( idx = 0, sl = byStart.length; idx < sl; idx++ ) {
for ( sl = byStart.length; sl > 0; sl-- ) {

if ( byStart[ idx ] && byStart[ idx ]._natives && byStart[ idx ]._natives.type === name ) {
if ( byStart[ sl ] && byStart[ sl ]._natives && byStart[ sl ]._natives.type === name ) {

byStart[ idx ]._natives._teardown && byStart[ idx ]._natives._teardown.call( obj, byStart[ idx ] );
byStart[ sl ]._natives._teardown && byStart[ sl ]._natives._teardown.call( obj, byStart[ sl ] );

byStart.splice( idx, 1 );
byStart.splice( sl, 1 );

// update for loop if something removed, but keep checking
idx--; sl--;
if ( obj.data.trackEvents.startIndex <= idx ) {
if ( obj.data.trackEvents.startIndex > sl ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this should be reversed?

I worry this was here to make sure if the currently indexed track event is removed, we are not forced to scrub forward and back to be able to get the proper index.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So yes, I am pretty sure you want to keep the old code, being <=

You also probably want to make sure it never goes below 0. If it currently is 0, and you're removing the first three track events, you want to keep it at 0, otherwise, you want to go back one.

obj.data.trackEvents.startIndex--;
obj.data.trackEvents.endIndex--;
}
}

// clean any remaining references in the end index
// we do this seperate from the above check because they might not be in the same order
if ( byEnd[ idx ] && byEnd[ idx ]._natives && byEnd[ idx ]._natives.type === name ) {
if ( byEnd[ sl ] && byEnd[ sl ]._natives && byEnd[ sl ]._natives.type === name ) {

byEnd.splice( idx, 1 );
byEnd.splice( sl, 1 );
}
}

//remove all animating events
for ( idx = 0, sl = animating.length; idx < sl; idx++ ) {
for ( sl = animating.length; sl > 0; sl-- ) {

if ( animating[ idx ] && animating[ idx ]._natives && animating[ idx ]._natives.type === name ) {
if ( animating[ sl ] && animating[ sl ]._natives && animating[ sl ]._natives.type === name ) {

animating.splice( idx, 1 );

// update for loop if something removed, but keep checking
idx--; sl--;
animating.splice( sl, 1 );
}
}

};

Popcorn.compositions = {};
Expand Down