-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Ensure members are initialized properly #39695
Conversation
Can you explain the rationale? There are hundreds of classes with members which are not default-initialized, but are also not used uninitialized as the class' logic always ensures that they're initialized before being used. If we think that everything should be default initialized (ah, if only that was a feature of C++ compilers...), this should be done as a coordinated effort and possibly with benchmarking of the potential performance impact, and not as individual PRs for every single class in the codebase. |
I do :)
Agreed! I'm coming (mainly) from outside the game-dev world where it is considered good practice to always have data in a consistent state. Over the decades I've dealt with many, many issues that resulted from uninitialized data. (In fact I'm looking into one right now.)
|
I can testify the uninitialized members issues and various heisenbugs throughout Godot, I've personally caught a few of them: #31604, #24283 (interestingly, all caught with the unit testing framework in place, and would probably left unnoticed without this). But yeah it would be better if this could be done on the entire codebase (?). But all or nothing doesn't quite work here IMO. I know that many programmers rely on logic and rationale, but issues like this demand intuition. And I feel like this particular PR could likely solve some problems already (mainly because I've stumbled upon some serialization issues already). To note, there was a major refactor regarding porting member default initialization from constructor to declaration #38697, but many places are still left uninitialized, like this: Lines 65 to 68 in 1f6f364
This sort of changes remind me of wanting to add some simple comments to document some parts of the engine internals, but then realizing that those changes would "unnecessarily pollute the |
If the project were to do this for the whole codebase (and I think it should - I can't think of any C++ project I've worked with/on in the last 25 years that doesn't initialize members by default - see reasoning above), it is not practical to do it all at once. If I were approaching it, I would first change the "dev docs" to say that all class and struct members should be initialized, then I would make the changes in a series of commits organized as much as possible around the filesystem structure. So directory-by-directory, trying to keep the PRs at a reasonable size to be reviewed quickly. I would probably have a standard commit message - something like "{init} Initialize members in [dir]". This would make it obvious it's part of this "project" and make them easier/faster to identify and review. These PRs would do 2 things:
Due to time and effort, I would only do this on the master branch rather than trying to do it on both 3.2 and 4.0. Again - I'm willing to spend the time on this if the powers-that-be approve. |
@asmaloney Is this still desired? If so, it needs to be rebased and tested on the latest master branch. |
It seems these have since been fixed in other PRs. It looks like the approach I mention to doing this systemically by folder is being done with #43636, though I think the "code style guidelines" still needs to be updated to say that all class and struct members should be initialized. |
(Actually, it looks like that issue is only covering what cppcheck finds, but it's better than nothing I suppose.) |
(PR for 3.2 here.)