So I started with line 3 and get an exception ( details below ). I then make line 1 and 2 to separate the two function calls and both lines work fine. But, when it gets to line 3 it still throws an exception.
This is in VS2022 with SDK 10.0, the toolset as v143, and the C++ language as latest. Debug build running the debugger.
OutputDebugString( "Setting x to y...\n" );
auto x = std::format( "Setting x to y level {}\n", ( int )level );
OutputDebugString( std::format( "Setting x to y level to {}\n", ( int )level ).c_str() );
The exception is in the function _CrtIsValidHeapPointer of debug_heap.cpp. I realize that indicates some form of memory corruption or bad pointer and I also am aware that the call might be causing the exception but it’s actually some other piece of code that is the culprit. At first I thought maybe the std::format library didn’t like the unsigned 16 bit value ( level ) so that’s why I cast it to an int but it didn’t make a difference.
I want to understand why this is happening and how I can debug it further. I wrapped it in a try/catch ( catch is for std::exception ) but the exception isn’t caught. It’s considered unhandled, I think, and VS just stops at that point in the debug_heap file. The command window does display “HEAP[TestProgram.exe]: Invalid address specified to RtlValidateHeap( 00650000, 18B9B0A0 )”.
How do you debug this issue?