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 memory leak on mesh collider destroy #5106

Merged
merged 28 commits into from
May 12, 2023

Conversation

MushAsterion
Copy link
Collaborator

Fixes #4267

I know it doesn't match the suggestion from the issue. However I think having a CollisionSystemImpl#destroyShape function sound more beneficial than making the parent class aware of an extension. It also removes override of the CollisionMeshSystemImpl#remove function and make sure there is an actual shape to destroy.

I confirm I have read the contributing guidelines and signed the Contributor License Agreement.

@willeastcott
Copy link
Contributor

Hey @LeXXik - you submitted the original issue. Got any thoughts here? 😄

@willeastcott willeastcott self-assigned this Feb 27, 2023
@willeastcott willeastcott added bug area: physics Physics related issue labels Feb 27, 2023
@LeXXik
Copy link
Contributor

LeXXik commented Feb 27, 2023

@willeastcott so, are we keeping the data object on the collision component then? I thought you might have been cooking an update for it, hence the last one didn't go through.

@MushAsterion, I think it would be good if we add a test that covers this change. If you are short on time, I can add it later this week. The test would need to cover at least clearing of the collision shapes (primitive, compounds, mesh and triggers). We don't need to test Ammo, so its methods can be stubbed. We just need to make sure we are calling the destroy methods on our side whenever needed.

@MushAsterion
Copy link
Collaborator Author

I think it would be good if we add a test that covers this change. If you are short on time, I can add it later this week. The test would need to cover at least clearing of the collision shapes (primitive, compounds, mesh and triggers). We don't need to test Ammo, so its methods can be stubbed. We just need to make sure we are calling the destroy methods on our side whenever needed.

That makes sense and time is not really a problem to me. However I have to admit that I have absolutely no knowledge or skills on this matter and when I look at the existing tests none already handle Ammo which sound quite complex to mirror especially on complex shapes... I would love to learn so if you have any example I can use to do so I'll be more than happy to give it a try!

@LeXXik
Copy link
Contributor

LeXXik commented Feb 28, 2023

@MushAsterion you can take a look at these tests that handle Ammo, as an example:

2a07dac

@MushAsterion
Copy link
Collaborator Author

Thank you @LeXXik! Took a bit of time but I managed to mirror Ammo based on the IDL from playcanvas/ammo.js repo and added the tests for destruction. Did my best to keep it simple but it might be still a bit messy...

I wasn't sure about creating a .mjs file only for Ammo but this way it keeps it separate since it is quite long. I know not all functions are used by the engine at the moment but as I was on it I just added everything based off the IDL so it won't cause issue if more features are used.

test/ammo.mjs Outdated Show resolved Hide resolved
Copy link
Contributor

@LeXXik LeXXik left a comment

Choose a reason for hiding this comment

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

This is amazing. I'd say you went a bit overkill with the Ammo stub module :) However, as you mentioned it can definitely be used to cover all current and potential future features we add to the engine.

Copy link
Contributor

@mvaligursky mvaligursky left a comment

Choose a reason for hiding this comment

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

The PR looks amazing. I added a small suggestion to the code, to make it slightly more compact.

The test looks a lot better than expected, I'm happy here.

Approving, but would like @willeastcott's thoughts here as well.

@MushAsterion
Copy link
Collaborator Author

MushAsterion commented May 11, 2023

The test looks a lot better than expected, I'm happy here.

In fact it was based on the ammo IDL from archived playcanvas/ammo.js, I think it might be useful to wait for the addition of latest Ammo.js version as @willeastcott told me it should come soon, unless it's not anymore it would then be beneficial to know the current IDL to make sure the Ammo tested version is the one actually used within editor as I was not aware the repo was outdated.

@mvaligursky
Copy link
Contributor

Perhaps you can then split this PR into two .. one which fixes the memory leak, and the test as a separate. This would allow us to merge the fix while waiting for latest Ammo.

MushAsterion added a commit to MushAsterion/playcanvas_engine that referenced this pull request May 12, 2023
@MushAsterion MushAsterion mentioned this pull request May 12, 2023
@MushAsterion
Copy link
Collaborator Author

Moved the tests to #5322!

@GSterbrant GSterbrant added the open source contribution Issues related to contributions from people outside the PlayCanvas team label May 12, 2023
Copy link
Contributor

@mvaligursky mvaligursky left a comment

Choose a reason for hiding this comment

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

Perfect, thanks!

@mvaligursky mvaligursky merged commit c30db18 into playcanvas:main May 12, 2023
7 checks passed
@MushAsterion MushAsterion deleted the fix-mesh-collider branch May 12, 2023 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: physics Physics related issue bug open source contribution Issues related to contributions from people outside the PlayCanvas team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Memory leak when mesh collider is used
5 participants