Skip to content

AS2: Array Splicing Involving Removed/Unloaded Movie Clips Doesn't Match Flash Player Behavior #5994

@pestoforce

Description

@pestoforce

Describe the bug

AS2: When splicing unloaded/removed movie clips from an array referencing them, Ruffle's behavior does not match Flash player.

.swf attached.

When attached .swf is run in Flash Player, the yellow MovieClips are unloaded fairly quickly, and the logs/trace statements show the length of the array steadily decreasing.

When attached .swf is run in Ruffle, the MovieClips take much longer to unload and the array's length logs as 100 always. Here is the attached .swf running via Ruffle: https://typehelp.org/ruffletest/splicetest.html

Minimally reproduced as2 code:

var allItems = new Array();
populateItems();

function populateItems() {
	for (var i=0; i<100; i++) {
		var g = this.attachMovie("guy", "g" + i, i);
		g._y = Math.floor(Math.random()*350);
		allItems.push(g);
	}
}

function randomRemove() {
	var doIt = Math.random() * 100;
	if (doIt < 30) {
		var randGuy = allItems[Math.floor(Math.random()*allItems.length)];
		randGuy.removeMovieClip();
		randGuy.unloadMovie();
	}
}

function sortClips() {
	trace("allItems length: " + allItems.length);
	for (var i=0; i<allItems.length; i++) {
		var s = allItems[i];
		if (s == undefined || s._y == undefined) {
			allItems.splice(i,1);
			i--;
			continue;
		}
	}
}

this.onEnterFrame = function() {
	sortClips();
	randomRemove();
}

Expected behavior

In Ruffle, the allItems array length would decrease from 100 to 0 as the file runs.

Affected platform

Self-hosted version

Operating system

Win 10

Browser

Chrome
splicetest.zip

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-avm1Area: AVM1 (ActionScript 1 & 2)bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions