Invalid bounds arguments passed to std::clamp

Thu Nov 25, 2021 9:08 am

In debug builds, it is possible to get an assertion failure error with the following message: "Invalid bounds arguments passed to std::clamp". This seems to depend on the screen size, so I'm attaching my ini file to help reproduce the issue.

To reproduce, start GZDoom and select the Heretic, Hexen, or Strife IWAD (for some reason this error does not appear when using a Doom IWAD). There is no need to fire up a level.

Tested in GZDoom g4.8pre-84-gaf54991c2.
You do not have the required permissions to view the files attached to this post.

Re: Invalid bounds arguments passed to std::clamp

Thu Nov 25, 2021 9:20 am

A stack trace would be more helpful. We got a similar report for Raze but are unable to reproduce it on any of the development systems.

Re: Invalid bounds arguments passed to std::clamp

Thu Nov 25, 2021 9:56 am

I've been able to successfully reproduce the issue on my laptop with the same INI file. The call stack is the following in all cases (regardless of the IWAD that is being used or whether or not -warp is specified):

Code:
>   gzdoom.exe!std::clamp<int,std::less<void>>(const int & _Val, const int & _Min_val, const int & _Max_val, std::less<void> _Pred) Line 10170   C++
    gzdoom.exe!std::clamp<int>(const int & _Val, const int & _Min_val, const int & _Max_val) Line 10190   C++
    gzdoom.exe!GetConScale(F2DDrawer * drawer, int altval) Line 168   C++
    gzdoom.exe!active_con_scale(F2DDrawer * drawer) Line 255   C++
    gzdoom.exe!C_DrawConsole() Line 579   C++
    gzdoom.exe!D_Display() Line 1086   C++
    gzdoom.exe!D_DoomLoop() Line 1219   C++
    gzdoom.exe!D_DoomMain_Internal() Line 3591   C++
    gzdoom.exe!GameMain() Line 3616   C++
    gzdoom.exe!DoMain(HINSTANCE__ * hInstance) Line 981   C++
    gzdoom.exe!wWinMain(HINSTANCE__ * hInstance, HINSTANCE__ * nothing, wchar_t * cmdline, int nCmdShow) Line 1270   C++
    [External Code]

However, when I was using debug builds to test my mod (which has a custom HUD) on my PC, the error happened in a different place, namely, when calling DStatusBarCore::SetClipRect. I am unable to reproduce this stack trace with a release build of the mod, and I don't have the current testing version here on my laptop. But if necessary, I can get it from my PC and test again - it will take some time though.

Re: Invalid bounds arguments passed to std::clamp

Thu Nov 25, 2021 10:05 am

It looks lilke these are ancient bugs that were silently accepted by our internal clamp function but seem to trip over the one from the STL...