fix(core): add nullptr check to mesh destructor to avoid segfault on mesh deletion #46
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bug overview
If the user attempts to delete a mesh using the
delete
keyword, the program will always segfault ifInitFromScene()
was not called. This issue is prevalent if the user implements scene-changes, or has short-lived objects that need their own mesh (e.g. bullets with random colors).The cause of this issue is that the mesh destructor attempts to call
ClearAnimations
andClearRootNode
even if these two objects have not been initialized (currently they are only set in theInitFromScene()
function). The simple fix for this is to check before-hand if these functions need to be called.The reason this might not have popped up as an issue before is because the default scene behaviour isn't to delete all values from the
meshes
hash map when the scene's destructor is called. For the lab assignments, this memory leak isn't a big issue.How to replicate
A simple way to replicate this is to modify
lab1.cpp
as such:And use this scene in
main.cpp
:I have tested this bug and the fix only on windows.