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

random order statics initialization #1

Open
abaddon201 opened this issue Feb 4, 2022 · 0 comments
Open

random order statics initialization #1

abaddon201 opened this issue Feb 4, 2022 · 0 comments

Comments

@abaddon201
Copy link

If you separate Components by different header files, you can get issue with wrong order of statics initialization. In this case, components factories vector can be initialized after all or some components, and in this case it can loose some values because of vector initialization. To fix this, you can change BaseComponent::sFactory with:
`

static std::vector<ComponentContainerFactory>& factories() {
    static std::vector<ComponentContainerFactory> sFactories;
    return sFactories;
}

`
in this case we can guarantee that factories vector is created and initialized before any actions with it.

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

1 participant