'Windows Open Dialog Box hangs forever with Address Sanitizer enabled
When Address Sanitizer is enabled, the Open Dialog Box cannot be shown. It hangs forever. Thank you.
It hangs when running hr = pFileOpen->Show(NULL);
#include <windows.h>
#include <shobjidl.h>
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
{
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED |
COINIT_DISABLE_OLE1DDE);
if (SUCCEEDED(hr))
{
IFileOpenDialog* pFileOpen;
// Create the FileOpenDialog object.
hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL,
IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));
if (SUCCEEDED(hr))
{
// Show the Open dialog box.
hr = pFileOpen->Show(NULL);
pFileOpen->Release();
}
CoUninitialize();
}
return 0;
}
Solution 1:[1]
The fix is available in current VS 2022 and VS 2019
Partial workaround for older VS:
To make this occur less often, add SetProcessAffinityMask(GetCurrentProcess(), 1);
at the beginning of your program. This seem to fix completely Open Dialog case, but doesn't fix more complex occurrences. (Be sure not to keep this workaround for normal program runs, as it effectively disables running on multiple CPU cores)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |