Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pestoforce opened this issue Jan 5, 2022 · 3 comments
Labels
A-avm1 Area: AVM1 (ActionScript 1 & 2) bug Something isn't working

Comments

@pestoforce
Copy link

pestoforce commented Jan 5, 2022

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

@pestoforce pestoforce added the bug Something isn't working label Jan 5, 2022
@pestoforce
Copy link
Author

splicetest.zip

@relrelb
Copy link
Contributor

relrelb commented Jan 7, 2022

This is just the already known "ghost" state that MovieClips become once removed:

var clip = this.createEmptyMovieClip("clip", 0);
trace(clip._y); // traces "0" in both Flash and Ruffle.
clip.removeMovieClip();
trace(clip._y); // traces "undefined" in Flash, but "0" in Ruffle.

Should be fixed by #5492.

@relrelb relrelb added the A-avm1 Area: AVM1 (ActionScript 1 & 2) label Jan 7, 2022
@relrelb
Copy link
Contributor

relrelb commented Mar 2, 2023

This was fixed by #9447, so closing.

@relrelb relrelb closed this as completed Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-avm1 Area: AVM1 (ActionScript 1 & 2) bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants