GamePad destructor crash and controlling compile options with cmake
trojanfoe opened this issue · comments
I have recently moved from using the vcxproj
VS projects of DirectXTK to cmake as using dependencies via cmake seems the most convenient and I am now experiencing a crash in the GamePad destructor:
if (mStatics)
{
(void)mStatics->remove_GamepadAdded(mAddedToken); <----
mAddedToken.value = 0;
(GamePad.cpp line 472).
Exception thrown: read access violation.
this->mStatics.ptr_->**** was 0x7FFD0C361F18.
My program is designed to be compiled for Win7 upwards and I note that this section is for Win10 (_WIN32_WINNT >= _WIN32_WINNT_WIN10
at line 390) and I cannot see a way to easily influence DirectXTK to compile for _WIN32_WINNT_WIN7
. When using the VS projects this is managed correctly.
Can you provide any suggestion on this issue?
Many thanks,
Andy
Setting this at the top of my CMakeLists.txt
file seems to do the trick:
add_definitions(-D_WIN32_WINNT=0x0601)
However this then upsets XAudio2.h
from the WIN10 SDK. Adding this doesn't solve things:
add_definitions(-D_WIN32_WINNT=0x0601 -DUSING_XAUDIO2_REDIST=1)
I have been unable to get the XAudio2 redist nuget package to work via CMake (in order to get the jigged xaudio2.h
file). VS_PACKAGE_REFERENCES
does not work for C++ projects apparently and manually installing the nuget package does not solve the issue - the project won't link against the redist header files, only the winsdk header files, which give the error because of the modified _WIN32_WINNT
value.
This is driven by BUILD_XAUDIO_WIN8
and BUILD_XAUDIO_WIN10
build options right now. If you want Windows 7 compat in CMake, you have to turn them both OFF which right now means no DirectX Tool Kit for Audio.
I'm working on getting a vcpkg port set up for the XAudio2Redist NuGet. Without it, there's no good way to reference it from CMake for Windows 7 compat.
Incidentally, before you fix your build issue, can you step through the GamePad ctor for the Windows 10 case and tell me how mStatics
ended up non-zero?
I would have expected a failure with mStatics
set to nullptr if you hadn't initilaized the Windows Runtime.
can you step through the GamePad ctor for the Windows 10
mStatics
is being initialized on line 433:
ThrowIfFailed(GetActivationFactory(HStringReference(RuntimeClass_Windows_Gaming_Input_Gamepad).Get(), mStatics.GetAddressOf()));
I hold a GamePad
instance and a GamePad::ButtonStateTracker
in my Game
and don't use them at the moment, other than to update the tracker every frame.
This is driven by BUILD_XAUDIO_WIN8 and BUILD_XAUDIO_WIN10
Ah this was unclear to me.
I'm working on getting a vcpkg port set up for the XAudio2Redist NuGet
That would probably help, thanks. In the meantime I've reverted to a project-based approach (concrete .sln
and .vcxproj
file for my project and the DirectXTK projects and cmake-generated projects for all other deps). Even then the DirectXTK audio project has to be modified as there is an assumption that packages are in ..\packages
and it's currently buried in External\DirectXTK\...
.
I would stick with vcpkg, which is promising. however I want to use static libraries and there is an assumption that that means I also want the static runtime... so cmake gives me the best options.
Ah just seen that there is a community triplet of x64-windows-static-md
which works as I want, so I'll go back to vcpkg
:) It looks like there is no XAudio2Redist option for DirectXTK Audio with vcpkg either though?
Right. I've got making a vcpkg port for XAudio2Redist on my backlog. It's a NuGet, so that's trivial to consume from MSBuild but not CMake.