Author Topic: Access violation while playing ADPCM streams on Windows 11 in 64-bit apps  (Read 866 times)

Jeroen Tandberg

  • Posts: 14
Hi! While working on our game engine, we've found out that there is a very weird and rare issue while trying to play MS-ADPCM wav files, which only manifests on a 64-bit builds of the engine.

If I understand correctly, BASS uses MSACM library to play MS-ADPCM data on Windows platforms. It seems that on some Windows 11 systems (we couldn't figure out the particular condition which leads to that - probably particular driver or corrupted system files or something else), MSACM library does not always work correctly, and BASS tends to crash with access violation while playing several MS-ADPCM streams at once. It is not specifically BASS issue, because e.g. NAudio also suffers the same problem, as it also uses MSACM to play MS-ADPCM files under the hood.

In case of BASS, it manifests like this:


Surprisingly, this issue does not exist on 32-bit builds (for both BASS and NAudio), so I smell some x86 vs x64 dll or driver conflict happening (e.g. Win11 has the same 32-bit msacm32.dll in both /System32 and /SysWOW64 folders, but it does not specifically mean something is wrong).

I don't have any idea how to fix this issue, because it seems to be a low-level system issue, but probably a try-catch block or some integrity check could be implemented to avoid crash of the library, and instead return error and continue running?

Thank you and best wishes! :)

Ian @ un4seen

  • Administrator
  • Posts: 25880
I don't seem to be able to reproduce that here. Is there a particular msacm32.dll version that the crash is happening with? And is it happening when playing particular MS-ADPCM file(s) or all? Please upload an affected file to try here:

   ftp.un4seen.com/incoming/

Please also provide a dump file from the crash for more info. The ProcDump tool can be used to generate the dump file. For example, run "procdump -e -ma -x . yourgame.exe".

Jeroen Tandberg

  • Posts: 14
Hi again, Ian! Thank you for fast response!  :)

I have uploaded wavs which cause troubles to your FTP (they didn't show up after uploading, so I am not sure I did it correctly - maybe I need some credentials?). But actually our contributor, who suffers from this issue, says that any MS-ADPCM file is provoking the crash. He also provided a dump file after the crash, but not sure if it wll be of any help: https://www.dropbox.com/s/8nzjwadtola5rxo/TombEngine.exe_230607_162914.dmp?dl=0

Ian @ un4seen

  • Administrator
  • Posts: 25880
Your files were received, thanks. Looking at the dump file, it appears that the crash was caused by the msadp32.acm file being unloaded for some reason (presumably by msacm32.dll) while still in use. To confirm whether that's the case, please try keeping msadp32.acm loaded by adding this line to your initialization code and see if the problem still happens then:

Code: [Select]
LoadLibrary("msadp32.acm");

Jeroen Tandberg

  • Posts: 14
Indeed, adding LoadLibrary call fixed the problem, thank you! :)
Could it be somehow implicitly done by BASS itself rather than introducing this hack into our codebase?

Ian @ un4seen

  • Administrator
  • Posts: 25880
Good to hear keeping msadp32.acm loaded fixes the problem. As you say, that's a bit hacky, and would still be so if BASS did it. I think I may have found a nicer solution though, so here's an update for you to try:

   www.un4seen.com/stuff/bass.zip

Please let me know if you still see the problem happen with that.

Jeroen Tandberg

  • Posts: 14
Unfortunately, our contributor who experienced that issue reports that crash is still happening with this new dll :(

Ian @ un4seen

  • Administrator
  • Posts: 25880
To confirm that it's the same as before, please upload a new dump file with the BASS update.

Is it only one Windows 11 user that's experiencing the crashes? The provided dump file didn't reveal their msadp32.acm version (because it was unloaded) but the msacm32.dll version is the same as I see on Windows 11 here. I haven't been able to reproduce a crash with that, but my tests probably aren't doing the same as your game. So it would be good to know if anyone else has the problem with your game, to see if it may be something system-specific.

Jeroen Tandberg

  • Posts: 14
Yes, currently it's just a single user who reported this crash. I think it's something very system-specific. I told him to run system file checker, but it returned no errors or corrupted files. Also I was suspecting that antivirus may cause this crash (in the past we had weird behaviour of antiviruses doing false alarms on classic TR engine reimplementations due to bad heuristics), but disabling Windows Defender also didn't solve the problem.

I asked him to provide new dump file and msadp32.acm file, will provide links when those will be online.

Jeroen Tandberg

  • Posts: 14
Okay, so here is the link to a new dump file: https://www.dropbox.com/s/7fvpvyoknq756vm/TombEngine.exe_230612_220006.dmp?dl=0

As well as the link to msadp32.acm file from our contributor's system, if you need it: https://cdn.discordapp.com/attachments/917486144281788517/1117931600198508634/msadp32.acm

Ian @ un4seen

  • Administrator
  • Posts: 25880
The new dump confirms that it is indeed the same problem as last time, ie. msadp32.acm is unloaded while in use. It's a bit strange that msadp32.acm is being unloaded at all, as msacm32 seems to usually keep all ACM codecs loaded even when they're not currently used, eg. after all streams have been freed. Does the game happen to be repeatedly loading and unloading the BASS library(s) dynamically, eg. it'll unload when nothing is playing? You can use Process Explorer's DLLs view to see what's currently loaded:

   https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer

To check whether the problem is specific to msadp32.acm, could you try using IMA ADPCM encoded files instead of MS ADPCM? A different ACM codec (imaadp32.acm) handles IMA ADPCM.

Jeroen Tandberg

  • Posts: 14
No, in our engine BASS is initialized once on startup and deinits when engine is closed. We only use BASS_Pause functions to stop tracks and samples, but nothing unusual.
Our tester reports that engine also crashes with IMA ADPCM wavs too, so it seems that ACM abruptly unloads any codec it previously loaded.

Ian @ un4seen

  • Administrator
  • Posts: 25880
So it appears to be a general ACM issue rather than specific to the MS ADPCM codec. To perhaps help narrow it down, please get them to see if they can reproduce it with the pre-compiled BASSTEST.EXE example included in the BASS package (C/BIN folder), eg. open/play/close the MS ADPCM files with its Stream options. And if the crash does happen then note when exactly.

Jeroen Tandberg

  • Posts: 14
We couldn't test precompiled basstest, because it's 32-bit, but I compiled it myself.
Repro steps are:

1. load up 2 tracks adpcm wavs
2. delete one wav track.
3. attempt to play the not deleted one

Another repro steps are:

1. load 2 tracks or 1 track
2. play the track
3. delete the track that plays

After that, crash happens.
« Last Edit: 18 Jun '23 - 17:01 by Jeroen Tandberg »

Ian @ un4seen

  • Administrator
  • Posts: 25880
Please provide a dump file from that 2nd scenario, where only 1 file is opened and played with BASSTEST, as that seems different to the previous. Please also provide their MSACM32.DLL file, just to confirm that it's the standard version.

Jeroen Tandberg

  • Posts: 14
Okay, here is the dump: https://cdn.discordapp.com/attachments/917486144281788517/1120661831040647240/basstest.exe_230620_112711.dmp

And msacm32.dll file: https://cdn.discordapp.com/attachments/917486144281788517/1120691724545708132/msacm32.dll

By the way, if you are familiar with ACM interface and maybe with NAudio, here is the log which is generated in our level editor which uses NAudio. I believe underlying cause is the same (it happens while trying to play ADPCM samples as well):

Code: [Select]
[12:08:28.155 ERROR] TombLib.Wad.WadSoundPlayer | Error while playing sample TombLib.Wad.WadSample, exception: NAudio.MmException: AcmNotPossible calling acmStreamOpen
   at NAudio.MmException.Try(MmResult result, String function)
   at NAudio.Wave.Compression.AcmStream..ctor(WaveFormat sourceFormat, WaveFormat destFormat)
   at NAudio.Wave.WaveFormatConversionProvider..ctor(WaveFormat targetFormat, IWaveProvider sourceProvider)
   at NAudio.Wave.WaveFormatConversionStream..ctor(WaveFormat targetFormat, WaveStream sourceStream)
   at TombLib.Wad.WadSoundPlayer.ResampleWaveStream(WaveStream originalStream)
   at TombLib.Wad.WadSoundPlayer.PlaySample(Level level, WadSample sample, Int32 channel, Single volume, Single pitch, Single pan, Int32 loopCount)

Ian @ un4seen

  • Administrator
  • Posts: 25880
Okay, here is the dump: https://cdn.discordapp.com/attachments/917486144281788517/1120661831040647240/basstest.exe_230620_112711.dmp

This dump file looks like it's from the 1st scenario you mentioned rather than the 2nd one, as the crash is in a BASS_ChannelPlay call (MSACM32.DLL is trying to access the unloaded codec within it). Perhaps they sent the wrong dump file? Please get a dump file from the 2nd scenario (open/play/close a single file), as that doesn't seem like it should trigger the unloaded codec crash.

And msacm32.dll file: https://cdn.discordapp.com/attachments/917486144281788517/1120691724545708132/msacm32.dll

This is the 32-bit version. Please get the 64-bit version, which can be found in the C:\WINDOWS\SYSTEM32 folder.

By the way, if you are familiar with ACM interface and maybe with NAudio, here is the log which is generated in our level editor which uses NAudio. I believe underlying cause is the same (it happens while trying to play ADPCM samples as well):

Code: [Select]
[12:08:28.155 ERROR] TombLib.Wad.WadSoundPlayer | Error while playing sample TombLib.Wad.WadSample, exception: NAudio.MmException: AcmNotPossible calling acmStreamOpen
...

In the dumps provided so far, it has always been acmStreamConvert that's crashed rather than acmStreamOpen, but I would guess it is indeed the same underlying problem of the ACM codec being unloaded. If you called BASS_StreamCreateFile to open an ADPCM WAV file straight after freeing another one, then that would probably result in an acmStreamOpen crash.

Can they reproduce the problem with Windows Media Player too, ie. does it crash/fail when trying to play 2 ADPCM files one after another?