Getting "error C4756: overflow in constant arithmetic" while building Unreal 5.4.2 from source code

This is valid when I package the engine source code, thank you very much!

Yes, I resolved the issue by compilling the project with the SDK version recommended in the “Unreal Engine Release Notes.”

Bit of a necro but I’d like to narrow down the fix to this problem.

I just successfully compiled a 5.4.4 engine version from source.

Fiddling with VS individual components from the visual studio install does not change which version of windows SDK is taken into account. You can uncheck the the latest version and check and older version and it doesn’t make a lick of difference.

Unreal’s build tool will automatically target the latest windows SDK and will cause the overflow error somewhere around the 4700 file compile mark.

To counteract this you need to manually edit the build configuration file at the path

Folder Where you have your unreal source\UnrealEngine\Engine\Saved\UnrealBuildTool\BuildConfiguration.xml

By default it’s pretty bare bones

<?xml version="1.0" encoding="utf-8" ?>
<Configuration xmlns="https://www.unrealengine.com/BuildConfiguration">
</Configuration>

You need to manually specify the SDK like this:

<?xml version="1.0" encoding="utf-8" ?>
<Configuration xmlns="https://www.unrealengine.com/BuildConfiguration">
<WindowsPlatform>
<WindowsSdkVersion>10.0.22621.0</WindowsSdkVersion>
</WindowsPlatform>
</Configuration>

I went with Windows Sdk Version 10.0.22621.0

10.0.26100.0 (lastest at this time) would cause crashes.

Make sure that while compiling when unreal displays the MSVC version and Win SDK version in the output windows that the version number matches the overridden one in the xml file.

This can save around 40 min of compile time if you know ahead of time that there is a mismatch.

16 Likes

It works,3q

it’s work, clean project and recomplile agian, thanks!

1 Like

Hello,

The best option in my opinion is to use the preprocessor variable _UCRT_LEGACY_INFINITY that has been added to the corecrt_math.h header:

That can be achieved by adding this line to the Build.cs file:

PublicDefinitions.Add("_UCRT_LEGACY_INFINITY");
2 Likes

Thank you Sir.

there is a commit which fix all issues for 4.27 with new win sdk
https://github.com/GapingPixel/UE5-PhysX-Vite/commit/37a8ebfb6cd50ba2533d0b36e0da1f4640268ec9

1 Like

To resume, options:

  1. Patching Unreal code as in @MeloinUnreal post. This is quite invasive fix though, but the right way to go. Should be accepted as a PR.

  2. Modify your C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt\corecrt_math.h

    #define INFINITY ((const float)“\x00\x00\x80\x7F”)

    This affects all your C++ projects though the change is benign. You will have to keep patching upcoming Windows SDK to keep it working.

  3. Patch your UnrealBuildTool, at Engine\Source\Programs\UnrealBuildTool\System\RulesAssembly.cs inside CreateTargetRulesInstance look for Rules.GlobalDefinitions setup and, for example, after:

    if (Rules.bDisableUnverifiedCertificates)
    {
    Rules.GlobalDefinitions.Add(“DISABLE_UNVERIFIED_CERTIFICATE_LOADING=1”);
    }

    Add:
    // workaround for “overflow in constant arithmetic” error using INFINITY macro
    Rules.GlobalDefinitions.Add(“_UCRT_LEGACY_INFINITY=1”);