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

Component references are calling the destrcutors #3

Open
Marco-v-BaldanII opened this issue Nov 19, 2024 · 1 comment
Open

Component references are calling the destrcutors #3

Marco-v-BaldanII opened this issue Nov 19, 2024 · 1 comment

Comments

@Marco-v-BaldanII
Copy link
Contributor

Marco-v-BaldanII commented Nov 19, 2024

@pepcots
In the Awake of Root.cpp we are creating the baker house. I took your advice from class and changed the Components work as variants than can hold either Transform or MeshRenderer components for now. The thing is i thought storing these variant components in a std::map would prevent them from being deleted but if i put breakPoints in the destructors of Component, Transform and MeshRenderer they are getting called like crazy. When i exit the scope of Root.cpp all components are presumbaly destroyed but later the transform seems to exist but not the Meshrenderer.

!!! im doing this in the "attempt-Components-with-variants" branch

Captura de pantalla 2024-11-19 172505

@pepcots
Copy link
Member

pepcots commented Nov 20, 2024

@Marco-v-BaldanII
When using a map, or any other container, you should always try to use the "emplace" approach:
https://en.cppreference.com/w/cpp/container/map/emplace
In your code, you are inserting items to the map by using random access:
map[key]=newItem
But this is making a default item in the [key] position, and then, copying newItem to there, so, what you see are the destructors of the rvalues (newItem).

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

No branches or pull requests

2 participants