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

fix: fix unintentional children mutation #586

Merged
merged 1 commit into from
Jan 15, 2025

Conversation

marianyp
Copy link
Contributor

In #562, a setter method for the parent property was introduced. This setter uses a .splice call to modify the children of the game object. However, in the remove game object method, we first set the parent to null, which triggers 1 splice call. Immediately after setting the parent to null, we perform another splice call. This is problematic because it results in 2 game objects being removed instead of 1.

Steps to reproduce:

  • Use the current master branch
  • Create a game with at least 2 game objects.
  • Delete the game object that was created first

Example:

const a = add([
	text("test 1", {
		size: 50
	}),
	color("#ff0000"),
	pos(width() / 2, height() / 2),
	fixed()
])

const b = add([
	text("test 2", {
		size: 50
	}),
	color("#ff0000"),
	pos(width() / 2, height() / 2 + 50),
	fixed()
])

a.destroy() // Results in both A and B being deleted

Copy link

pkg-pr-new bot commented Jan 14, 2025

Open in Stackblitz

npm i https://pkg.pr.new/kaplayjs/kaplay@586

commit: 1eb67d9

@lajbel lajbel requested a review from mflerackers January 15, 2025 11:45
@lajbel lajbel merged commit 7f34947 into kaplayjs:master Jan 15, 2025
2 checks passed
@lajbel lajbel added changelog This PR needs changelog and removed changelog This PR needs changelog labels Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants