Known Issues: XAudio 2.7


The XAudio2 library in the legacy DirectX SDK makes use of COM creation and reference counting for lifetime management, and a recent investigation has found a problem in this implementation. In short: in some situations the XAudio DLL itself is unloaded before the XAudio2 objects are completely destroyed, thus leading to an access violation. This normally happens on exit, although the exact details of when it might be evident depends on exactly which version of Windows you are using and the overall process layout for your application.

This issue does not affect XAudio 2.8 (Windows 8 SDK), XAudio 2.9 (Windows 10 SDK), XAudio2 on Xbox 360, or XAudio2 on Xbox One.

An application level workaround is very easy to implement, and is already implemented in DirectX Tool Kit for Audio and in the XAudio2 DirectX SDK refreshed samples on GitHub.

Before your first XAudio object creation, you should create an explicit reference to the DLL and hold on to it.

 #if ( _WIN32_WINNT < 0x0602 /*_WIN32_WINNT_WIN8*/)
 HMODULE g_XAudioDLL = nullptr;
 #endif
...

#if ( _WIN32_WINNT < 0x0602 /*_WIN32_WINNT_WIN8*/)
#ifdef _DEBUG
g_XAudioDLL = LoadLibraryExW( L"XAudioD2_7.DLL", nullptr, 0x00000800 /* LOAD_LIBRARY_SEARCH_SYSTEM32 */ );
#else
g_XAudioDLL = LoadLibraryExW( L"XAudio2_7.DLL", nullptr, 0x00000800 /* LOAD_LIBRARY_SEARCH_SYSTEM32 */ );
#endif
if ( !mXAudioDLL )
// error
#endif

...

DWORD creationFlags = 0;
#if (_WIN32_WINNT < 0x0602 /*_WIN32_WINNT_WIN8*/) && defined(_DEBUG)
creationFlags |= XAUDIO2_DEBUG_ENGINE;
#endif
IXAudio2* pXAudio2 = nullptr;
HRESULT hr = XAudio2Create( &pXAudio2, creationFlags, XAUDIO2_DEFAULT_PROCESSOR );
if ( FAILED(hr) )
// error

From here on, you work with XAudio2 as normal, delete objects, etc. Later after you do all cleanup and are fully done with working with XAudio2, you release the “extra” DLL reference:

 if (pXAudio2)
 pXAudio2->Release();
...

#if ( _WIN32_WINNT < 0x0602 /*_WIN32_WINNT_WIN8*/)
if (g_XAudioDLL)
{
FreeLibrary(g_XAudioDLL);
g_XAudioDLL = nullptr;
}
#endif

This ensures that the DLL is not unloaded while XAudio2 objects are active.

Note: The use of LoadLibraryEx above with the LOAD_LIBRARY_SEARCH_SYSTEM32 flag is a security best practice.  For a Windows 7 system, this requires the KB 2533623 update to be installed.

See also: XAudio2 and Windows 8, Learning XAudio2, Windows 10 SDK RTM

Comments (16)

  1. Kris says:

    Hello,

    Perhaps you could shed some light on apps crashing after 15 minutes relating to XAudio2_7.dll_unloaded? Since upgrading to Windows 10 this has affected quite a few games: Assassins Creed 4, Thief, Far Cry 3 and more. Searching for "XAudio2_7.dll_unloaded" shows other people with the issue.

    Is there a better system wide solution than disabling System32Xaudio2_7.dll and Syswow64Xaudio2_7.dll which often causes no sound for videos? Any chance of a hotfix?

    Example fault log:

    Faulting application name: AC4BFSP.exe, version: 0.0.0.0, time stamp: 0x5485bbbb

    Faulting module name: XAudio2_7.dll_unloaded, version: 9.29.1962.0, time stamp: 0x4c0641e5

    Exception code: 0xc0000005

    Fault offset: 0x0003a5e0

    Faulting process ID: 0x7b8

    Faulting application start time: 0x01d10e731c319bc0

    Faulting application path: I:SteamLibrarysteamappscommonAssassin's Creed IV Black FlagAC4BFSP.exe

    Faulting module path: XAudio2_7.dll

    System:

    Windows 10 Upgrade (From 8.1)

    i7 5820k, GTX 970

    Asus X-99a, Realtek® ALC1150 (Driver 6.0.1.7535)

    Thanks

  2. Ubisoft has already been informed of this issue. You should contact them to make sure they understand it is impacting customers.

  3. Andy says:

    Got the same issue with CAPCOM's Street Fighter IV. Is there any hotfix for this issue? like binary replacing? or this issue only occurs if you upgrade the OS from win7/8/8.1 to win10?

  4. The issue is already present on Windows 7, it just may or may not be noticeable.

  5. Bill says:

    Yes, well, since it's impacting many, many games that are no longer being patched, please make it not noticeable on windows 10 like it is on windows 7.

  6. @Bill – This specific issue does not affect many games as most use 3rd party middleware rather than XAudio. Which specific titles are you seeing an issue?

  7. Marc91 says:

    For your information, I've upgrade d from 8.1 to 10 and I have the same issue :

    Nom de l’application défaillante farcry3_d3d11.exe, version : 0.1.0.1, horodatage : 0x51226a2f

    Nom du module défaillant : XAudio2_7.dll_unloaded, version : 9.29.1962.0, horodatage : 0x4c0641e5

    Code d’exception : 0xc0000005

    Décalage d’erreur : 0x0003a5e0

    ID du processus défaillant : 0x960

    Heure de début de l’application défaillante : 0x01d125e0069a7214

    Chemin d’accès de l’application défaillante : D:JeuxSteamsteamappscommonFar Cry 3binfarcry3_d3d11.exe

    Chemin d’accès du module défaillant: XAudio2_7.dll

    ID de rapport : aff83afe-28f8-4935-a0b9-60704e520507

    Nom complet du package défaillant :

    ID de l’application relative au package défaillant :

    I've tried all solutions provided here and elsewhere without success.

  8. Laurent says:

    Dear all, I have the same problem with Van Helsing III on Win 10, and before that with Van Helsing II on Win 8.1.

    I can play about ten minutes then the game crashes because of Xaudio2_7.dll is unloaded

    :'(

    Nothing much I can do.

    cheers

  9. Evgenii says:

    Hi Chuck,

    I work on a commercial title that uses XAudio2 on Windows and we've seen many crashes and application hangs coming in only from Windows 10 and 8 systems. They seem to occur most frequently when unplugging USB devices or disabling them through the control panel while the game is running. This workaround fixes a few of the crashes, but some crashes and the hang continue to occur. I've also managed to replicate the issue with a modified sample application, as well as in applications using middleware such as Wwise (albeit slightly harder to reproduce). Is this a known issue? I can provide more information if you can provide a better channel to discuss this through.

    Thanks,

    Evgenii

  10. Steve126484 says:

    The actual problem may be with a Windows 10 Service named, “Touch Keyboard and Handwriting Panel Service” which seems to be causing a fault with the DLL in question. To solve this error problem:

    1. Click on Start and type, Services.msc to open the Services interface.
    2. Find the “Touch Keyboard and Handwriting Panel Service” and stop the services.
    3. Confirm this is your solution by playing the game. If this solves it, go to step 4.
    4. Right-click the service and go to Properties.
    5. On the General tab, go to the Startup Type and set it to Manual or Disabled if preferred.
    6. Click OK and close the Services interface.

  11. Microsoft, please resolve this issue. I’m experiencing these crash symtoms too on a new Surface book, which I spent over £2k on. If I play a game on the device it crashes after 10-15 minutes. To resolve this I simply have to disable and stop the “Touch Keyboard and Handwriting Panel Service” service on my computer. This isn’t a great workaround as it makes the surface book useless in an undocked state.

    1. Eric Willeke says:

      Seeing the same symptoms – seems to impact the Surface Pro 4 quite a bit as well. For me it’s currently Kingdoms of Amalur: Reckoning. Is there a repaired version of the library available?

      1. The title developer is the one in a position to resolve the issue. Please contact the developer/publisher.

  12. Harvey says:

    I really don’t know what I’m supposed to do! Sorry!

    1. This post is for developers using XAudio 2.7 in their applications. If you aren’t a developer, there’s nothing here for you to do.

  13. Modrick says:

    that’s awesome! just solved problem with your article

Skip to main content