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

Don't override KinematicCollision reference when still in use in script #52954

Merged

Conversation

pouleyKetchoupp
Copy link
Contributor

In case the reference is stored in script, create a new instance to avoid overriding the previous values.
Otherwise, re-use the reference as before to avoid extra allocations.

Fixes #36290

In case the reference is stored in script, create a new instance to
avoid overriding the previous values.
Otherwise, re-use the reference as before to avoid extra allocations.
@KoBeWi
Copy link
Member

KoBeWi commented Sep 23, 2021

Wouldn't it be better to return a copy of the collision when accessing from script? This way you wouldn't need to worry if it's used or not.

@pouleyKetchoupp
Copy link
Contributor Author

Wouldn't it be better to return a copy of the collision when accessing from script? This way you wouldn't need to worry if it's used or not.

That would mean doing an allocation on each call, whereas checking for references allows the original optimization to still work in common cases.

@akien-mga akien-mga merged commit 2815594 into godotengine:master Sep 23, 2021
@akien-mga
Copy link
Member

Thanks!

@pouleyKetchoupp pouleyKetchoupp deleted the fix-kinematic-collision-reference branch September 23, 2021 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KinematicCollision2D is overriden even though the variable isn't reassigned
3 participants