spdlog icon indicating copy to clipboard operation
spdlog copied to clipboard

[MSVC 17.10.5] spdlog::sinks::base_sink<Mutex>::set_pattern() crash

Open tksuoran opened this issue 1 year ago • 3 comments

The following code crashes for me, when building with MSVC in Release or RelWithDebInfo configurations:

#include <spdlog/sinks/basic_file_sink.h>

auto main(int, char**) -> int
{
    std::shared_ptr<spdlog::sinks::basic_file_sink_mt> sink_log_file;
    sink_log_file = std::make_shared<spdlog::sinks::basic_file_sink_mt>("log.txt", true);
    sink_log_file->set_pattern("[%H:%M:%S %z] [%n] [%L] [%t] %v"); // This crashes
    return 0;
}

I am using MSVC 17.10.5, Windows 11.

Callstack:

 	msvcp140.dll!00007ffb81833020()	Unknown
>	[Inline Frame] editor.exe!std::_Mutex_base::lock() Line 52	C++
 	[Inline Frame] editor.exe!std::lock_guard<std::mutex>::{ctor}(std::mutex &) Line 458	C++
 	[Inline Frame] editor.exe!spdlog::sinks::base_sink<std::mutex>::set_pattern(const std::string &) Line 39	C++
 	editor.exe!main(int __formal, char * * __formal) Line 7	C++
 	[Inline Frame] editor.exe!invoke_main() Line 78	C++
 	editor.exe!__scrt_common_main_seh() Line 288	C++
 	kernel32.dll!00007ffb93c6257d()	Unknown
 	ntdll.dll!00007ffb93f6af28()	Unknown

Output in VS:

'editor.exe' (Win32): Loaded 'C:\git\tksuoran\alt\erhe\src\editor\RelWithDebInfo\editor.exe'. Symbols loaded.
'editor.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. Symbol loading disabled by Include/Exclude setting.
'editor.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. Symbol loading disabled by Include/Exclude setting.
'editor.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. Symbol loading disabled by Include/Exclude setting.
'editor.exe' (Win32): Loaded 'C:\Windows\System32\advapi32.dll'. Symbol loading disabled by Include/Exclude setting.
'editor.exe' (Win32): Loaded 'C:\Windows\System32\msvcrt.dll'. Symbol loading disabled by Include/Exclude setting.
'editor.exe' (Win32): Loaded 'C:\Windows\System32\sechost.dll'. Symbol loading disabled by Include/Exclude setting.
'editor.exe' (Win32): Loaded 'C:\Windows\System32\bcrypt.dll'. Symbol loading disabled by Include/Exclude setting.
'editor.exe' (Win32): Loaded 'C:\Windows\System32\rpcrt4.dll'. Symbol loading disabled by Include/Exclude setting.
'editor.exe' (Win32): Loaded 'C:\Windows\System32\ws2_32.dll'. Symbol loading disabled by Include/Exclude setting.
'editor.exe' (Win32): Loaded 'C:\Windows\System32\user32.dll'. Symbol loading disabled by Include/Exclude setting.
'editor.exe' (Win32): Loaded 'C:\Windows\System32\win32u.dll'. Symbol loading disabled by Include/Exclude setting.
'editor.exe' (Win32): Loaded 'C:\Windows\System32\gdi32.dll'. Symbol loading disabled by Include/Exclude setting.
'editor.exe' (Win32): Loaded 'C:\Windows\System32\gdi32full.dll'. Symbol loading disabled by Include/Exclude setting.
'editor.exe' (Win32): Loaded 'C:\Windows\System32\msvcp_win.dll'. Symbol loading disabled by Include/Exclude setting.
'editor.exe' (Win32): Loaded 'C:\Windows\System32\ucrtbase.dll'. Symbol loading disabled by Include/Exclude setting.
'editor.exe' (Win32): Loaded 'C:\Windows\System32\shell32.dll'. Symbol loading disabled by Include/Exclude setting.
'editor.exe' (Win32): Loaded 'C:\Windows\System32\ole32.dll'. Symbol loading disabled by Include/Exclude setting.
'editor.exe' (Win32): Loaded 'C:\Windows\System32\combase.dll'. Symbol loading disabled by Include/Exclude setting.
'editor.exe' (Win32): Loaded 'C:\Windows\System32\imm32.dll'. Symbol loading disabled by Include/Exclude setting.
'editor.exe' (Win32): Loaded 'C:\Windows\System32\msvcp140.dll'. Symbol loading disabled by Include/Exclude setting.
'editor.exe' (Win32): Loaded 'C:\Windows\System32\msvcp140_atomic_wait.dll'. Symbol loading disabled by Include/Exclude setting.
'editor.exe' (Win32): Loaded 'C:\Windows\System32\msvcp140_1.dll'. Symbol loading disabled by Include/Exclude setting.
'editor.exe' (Win32): Loaded 'C:\Windows\System32\dbghelp.dll'. Symbol loading disabled by Include/Exclude setting.
'editor.exe' (Win32): Loaded 'C:\Windows\System32\oleaut32.dll'. Symbol loading disabled by Include/Exclude setting.
'editor.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140.dll'. Symbol loading disabled by Include/Exclude setting.
'editor.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140_1.dll'. Symbol loading disabled by Include/Exclude setting.
The thread 79688 has exited with code 0 (0x0).
Exception thrown at 0x00007FFB81833020 (msvcp140.dll) in editor.exe: 0xC0000005: Access violation reading location 0x0000000000000000.

I suspect this might be caused by some of the compiler/linker flags I set in my project. I moved the code to main but kept my other project the same. Here are all command line options for main.cpp:

/JMC /MP /ifcOutput "editor.dir\RelWithDebInfo\" /GS /external:anglebrackets /W4 /Zc:wchar_t /I"C:\git\tksuoran\alt\erhe\src\editor" /I"C:\git\tksuoran\alt\erhe\src\erhe\bit" /I"C:\git\tksuoran\alt\erhe\src\erhe\commands" /I"C:\git\tksuoran\alt\erhe\src\erhe\xr" /I"C:\git\tksuoran\alt\erhe\src\erhe\gl" /I"C:\git\tksuoran\alt\erhe\build\src\erhe\gl" /I"C:\git\tksuoran\alt\erhe\src\khronos\khronos" /I"C:\git\tksuoran\alt\erhe\build\_deps\fmt-src\include" /I"C:\git\tksuoran\alt\erhe\src\erhe\window" /I"C:\git\tksuoran\alt\erhe\src\erhe\time" /I"C:\git\tksuoran\alt\erhe\build\_deps\glfw-src\include" /I"C:\git\tksuoran\alt\erhe\build\_deps\glm-src" /I"C:\git\tksuoran\alt\erhe\build\_deps\openxr-sdk-src\include" /I"C:\git\tksuoran\alt\erhe\build\_deps\openxr-sdk-build\include" /I"C:\git\tksuoran\alt\erhe\build\_deps\cxxopts-src\include" /I"C:\git\tksuoran\alt\erhe\src\erhe\concurrency" /I"C:\git\tksuoran\alt\erhe\build\_deps\concurrentqueue-src" /I"C:\git\tksuoran\alt\erhe\src\erhe\graphics" /I"C:\git\tksuoran\alt\erhe\src\erhe\configuration" /I"C:\git\tksuoran\alt\erhe\src\mINI\include" /I"C:\git\tksuoran\alt\erhe\src\erhe\dataformat" /I"C:\git\tksuoran\alt\erhe\src\erhe\log" /I"C:\git\tksuoran\alt\erhe\build\_deps\spdlog-src\include" /I"C:\git\tksuoran\alt\erhe\src\erhe\verify" /I"C:\git\tksuoran\alt\erhe\src\erhe\item" /I"C:\git\tksuoran\alt\erhe\src\erhe\profile" /I"C:\git\tksuoran\alt\erhe\src\mango\include" /I"C:\git\tksuoran\alt\erhe\src\erhe\ui" /I"C:\git\tksuoran\alt\erhe\src\erhe\primitive" /I"C:\git\tksuoran\alt\erhe\src\erhe\geometry" /I"C:\git\tksuoran\alt\erhe\src\erhe\math" /I"C:\git\tksuoran\alt\erhe\src\erhe\raytrace" /I"C:\git\tksuoran\alt\erhe\src\erhe\hash" /I"C:\git\tksuoran\alt\erhe\build\_deps\bvh-src\src" /I"C:\git\tksuoran\alt\erhe\src\erhe\defer" /I"C:\git\tksuoran\alt\erhe\src\erhe\file" /I"C:\git\tksuoran\alt\erhe\src\erhe\gltf" /I"C:\git\tksuoran\alt\erhe\src\erhe\imgui" /I"C:\git\tksuoran\alt\erhe\src\erhe\rendergraph" /I"C:\git\tksuoran\alt\erhe\src\imgui" /I"C:\git\tksuoran\alt\erhe\build\_deps\freetype-build\include" /I"C:\git\tksuoran\alt\erhe\build\_deps\freetype-src\include" /I"C:\git\tksuoran\alt\erhe\src\erhe\net" /I"C:\git\tksuoran\alt\erhe\src\erhe\physics" /I"C:\git\tksuoran\alt\erhe\build\_deps\joltphysics-src\Build\.." /I"C:\git\tksuoran\alt\erhe\src\erhe\renderer" /I"C:\git\tksuoran\alt\erhe\src\erhe\scene" /I"C:\git\tksuoran\alt\erhe\src\erhe\message_bus" /I"C:\git\tksuoran\alt\erhe\src\erhe\scene_renderer" /I"C:\git\tksuoran\alt\erhe\src\RectangleBinPack" /I"C:\git\tksuoran\alt\erhe\src\rapidjson\include" /I"C:\git\tksuoran\alt\erhe\build\_deps\taskflow-src" /I"C:\git\tksuoran\alt\erhe\build\_deps\lunasvg-src\include" /Zi /Gm- /O2 /Ob1 /Fd"editor.dir\RelWithDebInfo\vc143.pdb" /Zc:inline /fp:fast /external:W0 /D "_MBCS" /D "WIN32" /D "_WINDOWS" /D "NDEBUG" /D "UNICODE" /D "NOMINMAX" /D "_CRT_SECURE_NO_WARNINGS" /D "_SILENCE_CXX20_U8PATH_DEPRECATION_WARNING" /D "GLM_FORCE_PURE" /D "GLM_FORCE_CXX2A=1" /D "GLM_FORCE_DEPTH_ZERO_TO_ONE" /D "FMT_HEADER_ONLY" /D "ERHE_DLOAD_ALL_GL_SYMBOLS" /D "ERHE_OS_WINDOWS" /D "SPDLOG_FMT_EXTERNAL" /D "GLM_ENABLE_EXPERIMENTAL" /D "ERHE_TERMINAL_LIBRARY_NONE" /D "ERHE_AUDIO_LIBRARY_NONE" /D "ERHE_SVG_LIBRARY_LUNASVG" /D "ERHE_GLTF_LIBRARY_FASTGLTF" /D "ERHE_PROFILE_LIBRARY_NONE" /D "ERHE_GUI_LIBRARY_IMGUI" /D "ERHE_FONT_RASTERIZATION_LIBRARY_FREETYPE" /D "ERHE_TEXT_LAYOUT_LIBRARY_HARFBUZZ" /D "ERHE_WINDOW_LIBRARY_GLFW" /D "ERHE_RAYTRACE_LIBRARY_BVH" /D "JPH_FLOATING_POINT_EXCEPTIONS_ENABLED" /D "ERHE_PHYSICS_LIBRARY_JOLT" /D "ERHE_XR_LIBRARY_OPENXR" /D "ERHE_TRACY_GL" /D "JPH_OBJECT_STREAM" /D "JPH_USE_AVX2" /D "JPH_USE_AVX" /D "JPH_USE_SSE4_1" /D "JPH_USE_SSE4_2" /D "JPH_USE_LZCNT" /D "JPH_USE_TZCNT" /D "JPH_USE_F16C" /D "JPH_USE_FMADD" /D "CMAKE_INTDIR=\"RelWithDebInfo\"" /fp:except- /errorReport:prompt /WX /Zc:forScope /arch:AVX2 /Gd /MD /std:c++20 /FC /Fa"editor.dir\RelWithDebInfo\" /EHsc /nologo /Fo"editor.dir\RelWithDebInfo\" /Fp"editor.dir\RelWithDebInfo\editor.pch" /diagnostics:column 

tksuoran avatar Jul 26 '24 17:07 tksuoran

Maybe duplicate https://github.com/gabime/spdlog/issues/3119#issuecomment-2218733127

MSVC has incompatible changes to std::mutex (microsoft/STL#4730). If you are using MSVC version 17.10 or later, VIsual Studio Runtime will also crash if version 17.10 or later is not used.

tt4g avatar Jul 26 '24 20:07 tt4g

It looks like that. However, I build everything from sources using cmake and msvc, including third party code (cmake fetch content, spdlog for example), and the crash happens on the same computer, right inside when running in Visual Studio. So I cannot quite figure out how it breaks nor how to fix it.

tksuoran avatar Jul 26 '24 21:07 tksuoran

Please install the latest version of Microsoft Visual C++ Redistributable (https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170) and see if the problem reproduces again.

tt4g avatar Jul 26 '24 21:07 tt4g

These are modules of my test program before trying to updating VC redistributable: image I downloaded and run the installer Microsoft Visual C++ 2015-2022 Redistributable (x64) - 14.40.33810 It gave me options Repair and Uninstall, this suggests that I already had it installed. Which made sense, since I would assume installing Visual Studio does the installation. I run the Repair option. Now it wants to reboot, I'll report back after I've rebooted.

tksuoran avatar Jul 27 '24 06:07 tksuoran

After reboot: image And the issue is gone! Thanks!

tksuoran avatar Jul 27 '24 06:07 tksuoran