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 weird MSVC compilation error #97059

Merged

Conversation

Gaktan
Copy link
Contributor

@Gaktan Gaktan commented Sep 15, 2024

For some reason, MSVC doesn't appreciate uint8 math with enum constants.
I have no idea why I didn't have this error until a few weeks ago. The incriminating code was has not been changed recently which is super weird.
I still had the error even after updating VS2019.

The error is caused by the use of << FRAC_BITS inside the if constexpr (sizeof(T) == 1) { condition in _scale_bilinear.
I tried a few different things, but declaring FRAC_BITS as uint32 seems to be the only thing that works.
It doesn't hurt to clean the code though, using an enum to store constants is error prone, since the type is inferred by the compiler.

Error log:

1>core\io\image.cpp(4325): fatal error C1001: Internal compiler error.
1>(compiler file 'D:\a\_work\1\s\src\vctools\Compiler\CxxFE\sl\p1\c\PackExpander.cpp', line 2441)
1> To work around this problem, try simplifying or changing the program near the locations listed above.
1>If possible please provide a repro here: https://developercommunity.visualstudio.com
1>Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more information
1>core\io\image.cpp(1272): note: see reference to function template instantiation 'void _scale_bilinear<1,uint8_t>(const uint8_t *__restrict ,uint8_t *__restrict ,uint32_t,uint32_t,uint32_t,uint32_t)' being compiled

For some reason, MSVC doesn't appreciate uint8 math with enum constants
@akien-mga
Copy link
Member

This should be reported to Microsoft as a bug in MSVC, since it's an internal compiler error on valid code.

The proposed workaround might be fine to merge to solve it downstream but ideally the bug should be fixed in the compiler, so we don't run into it in other cases.

@akien-mga akien-mga merged commit a6d84bc into godotengine:master Sep 16, 2024
20 checks passed
@akien-mga
Copy link
Member

Thanks!

@Gaktan Gaktan deleted the fix_weird_msvc_compilation_error branch September 17, 2024 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants