microsoft / DirectXTK

The DirectX Tool Kit (aka DirectXTK) is a collection of helper classes for writing DirectX 11.x code in C++
https://walbourn.github.io/directxtk/
MIT License
2.55k stars 506 forks source link

Errors using AudioEngine_UseMasteringLimiter #92

Closed PeteHuf closed 7 years ago

PeteHuf commented 7 years ago

I'm trying to add the AudioEngine_UseMasteringLimiter flag to my AudioEngine construct. My total set is: AudioEngine_Default | AudioEngine_Debug | AudioEngine_EnvironmentalReverb | AudioEngine_ReverbUseFilters | AudioEngine_UseMasteringLimiter. I'm going through the

hr = CreateFX( __uuidof(FXMasteringLimiter), mVolumeLimiter.ReleaseAndGetAddressOf() );

version of CreateFX in AudioEngine::Impl::Reset. When I do, I get one of two errors (seems a bit random):

Error 1: Exception thrown at 0x00007FF98AD82430 (XAudio2_9.dll) in Biodrome.exe: 0xC0000005: Access violation reading location 0x000000000000011C.

XAudio2_9.dll!XAPOFX::CFXEcho::Initialize(void const *,unsigned int)    Unknown
XAudio2_9.dll!CreateFX()   Unknown
Biodrome.exe!DirectX::AudioEngine::Impl::Reset(const tWAVEFORMATEX * wfx, const wchar_t * deviceId) Line 591    C++
Biodrome.exe!DirectX::AudioEngine::Impl::Initialize(DirectX::AUDIO_ENGINE_FLAGS flags, const tWAVEFORMATEX * wfx, const wchar_t * deviceId, _AUDIO_STREAM_CATEGORY category) Line 357   C++
Biodrome.exe!DirectX::AudioEngine::AudioEngine(DirectX::AUDIO_ENGINE_FLAGS flags, const tWAVEFORMATEX * wfx, const wchar_t * deviceId, _AUDIO_STREAM_CATEGORY category) Line 1249   C++
Biodrome.exe!std::make_unique<DirectX::AudioEngine,enum DirectX::AUDIO_ENGINE_FLAGS & __ptr64>(DirectX::AUDIO_ENGINE_FLAGS & <_Args_0>) Line 2054   C++
Biodrome.exe!xpl::eng::Audio::initialize(const std::vector<xpl::data::Sound_pack,std::allocator<xpl::data::Sound_pack> > & sounds_packs) Line 381   C++

Error 2: XAUDIO2: ERROR: Effect descriptor: pEffect does not point to an XAPO

XAudioD2_7.dll!XAudio2Trace(unsigned int,char const *,unsigned int,char const *,char const *,...)   Unknown
XAudioD2_7.dll!XAUDIO2::CX2EffectChain::ValidateEffectChain(struct XAUDIO2_EFFECT_CHAIN const *,unsigned int)   Unknown
XAudioD2_7.dll!XAUDIO2::CX2Voice::SetEffectChain(struct XAUDIO2_EFFECT_CHAIN const *)   Unknown
Biodrome.exe!DirectX::AudioEngine::Impl::Reset(const tWAVEFORMATEX * wfx, const wchar_t * deviceId) Line 606    C++
Biodrome.exe!DirectX::AudioEngine::Impl::Initialize(DirectX::AUDIO_ENGINE_FLAGS flags, const tWAVEFORMATEX * wfx, const wchar_t * deviceId, _AUDIO_STREAM_CATEGORY category) Line 357   C++
Biodrome.exe!DirectX::AudioEngine::AudioEngine(DirectX::AUDIO_ENGINE_FLAGS flags, const tWAVEFORMATEX * wfx, const wchar_t * deviceId, _AUDIO_STREAM_CATEGORY category) Line 1249   C++
Biodrome.exe!std::make_unique<DirectX::AudioEngine,enum DirectX::AUDIO_ENGINE_FLAGS & __ptr64>(DirectX::AUDIO_ENGINE_FLAGS & <_Args_0>) Line 2054   C++
Biodrome.exe!xpl::eng::Audio::initialize(const std::vector<xpl::data::Sound_pack,std::allocator<xpl::data::Sound_pack> > & sounds_packs) Line 381   C++

Let me know if more info about my usage would be helpful. The issue still repros when I remove the reverb related flags.

walbourn commented 7 years ago

One stack-dump is when using XAudio 2.9 which is Windows 10 only. The other stack dump is when using down-level XAudio 2.7. You can't mix the use of these in the same compilation module, so are these two different EXE versions?

PeteHuf commented 7 years ago

I hadn't noticed the two version before. I'm trying to use 2.7. I have _WIN32_WINNT == 0x0600. It seems to end up either place randomly, even with the same version of the exe. I haven't been able to find a pattern.

The 2.9 callstack is entering though the following line:

hr = CreateFX( __uuidof(FXMasteringLimiter), mVolumeLimiter.ReleaseAndGetAddressOf() );

Which I believe is the SDK version (2.7)? I suspect I have my project misconfigured. Is the "DirectXTKAudio_Desktop_2015_DXSDK" project's "VC++ Directories" the right place to try to fix that? I tried pointing it to the SDK directories which I downloaded, but I haven't seen that change any of the behavior.

Just when I thought I was starting to understand VS projects. :)

walbourn commented 7 years ago

Yes, you do seem to be having a mix of versions which would result in problems. Be sure you have _WIN32_WINNT set before any other headers are included (I'd suggest using 0x0601 for Windows 7 SP1 compat; 0x0600 is Windows Vista SP2 which is end-of-life at this point). Typically it's set as follows in a pch header:

#include <WinSDKVer.h>
#define _WIN32_WINNT 0x0601
#include <SDKDDKVer.h>

I'd also check that you have the include/lib paths set correct for mixing the legacy DirectX SDK with the Windows 8.1 SDK for your project (particularly your EXE where the final link is done). They need to be set to:

For 32-bit (x86):

<ExecutablePath>$(ExecutablePath);$(DXSDK_DIR)Utilities\bin\x86</ExecutablePath>
<IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>
<LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\x86</LibraryPath>

For 64-bit (x64):

<ExecutablePath>$(ExecutablePath);$(DXSDK_DIR)Utilities\bin\x64;$(DXSDK_DIR)Utilities\bin\x86</ExecutablePath>
<IncludePath>$(IncludePath);$(DXSDK_DIR)Include</IncludePath>
<LibraryPath>$(LibraryPath);$(DXSDK_DIR)Lib\x64;</LibraryPath>

The Audio.h header has the following setup to try to get the right link libraries:

#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/)
#if defined(_MSC_VER) && (_MSC_VER < 1700)
#error DirectX Tool Kit for Audio does not support VS 2010 without the DirectX SDK 
#endif
#include <xaudio2.h>
#include <xaudio2fx.h>
#include <x3daudio.h>
#include <xapofx.h>
#pragma comment(lib,"xaudio2.lib")
#else
// Using XAudio 2.7 requires the DirectX SDK
#include <C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\comdecl.h>
#include <C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\xaudio2.h>
#include <C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\xaudio2fx.h>
#include <C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\xapofx.h>
#pragma warning(push)
#pragma warning( disable : 4005 )
#include <C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\x3daudio.h>
#pragma warning(pop)
#pragma comment(lib,"x3daudio.lib")
#pragma comment(lib,"xapofx.lib")
#endif

If you ended up linking with xaudio2.lib, then you would be using XAudio 2.9 but with the 2.7 headers. In other words, a mess.

PeteHuf commented 7 years ago

Thanks @walbourn! I was busy on a different area of the game for a while, but came back to this today. The critical failure was a project where I'd missed defining the correct _WIN32_WINNT. I found it by putting a static_assert(false) in the #if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/) block you mentioned above.

The program now runs with the limiter in place. Closing this question. Thanks again!