c - SDL_Mixer: Mix_FreeChunk() crashing on sample created in memory -
I was working on adding random pitch to the samples, and it works just fine, but Mix_FreeChunk ( ) The part after using it while trying to free the accidents.
I did a simple test to recreate this issue (SDL 1.2.14 and SDL_mixer 1.2.11):
Mix_Chunk * S1 = rexResourceMgr-> GetSoundFromFile ("Data / Audio / UI / ALARM.ogg"); Use Mix_LoadWAV_RW / SDL_RWops to load the sample Mix_Chunk * s2 = (Mix_Chunk *) Molec (Mix_Chunk); S2-> Allocated = 1; S2-> Allan = s1-> Ellen; S2-> Abuf = (Uint8 *) Mallow (s2-> Allen * Volume (Uint8)); Memcpy (S2-> abuf, s1-> abuf, s2-> allen); S2-> gt; Quantity = s1-> Volume; Mix_FreeChunk (S1); // & lt; - Mix_FreeChunk works fine (s2); // & lt; - Accidents are loaded anywhere in SDL / SDL_Mixer using the S1 Mix_loaded_rW file, and is the exact copy of the S1 created in S2 memory. The latter does not precede the accidents, but the former does. Someone also realizes why this can happen? I've spent a few hours on this and have narrowed it down to occur in SDL_Mixer, but I have no way to see what is going on in the underlying source when it crashes, and now this test Very simple The exact copy of the original sample , but still fails ... An example of a specific error message: "0x77c5e3be first chance at game.exe: 0xC0000005: Establishment of admission violation NO 0x69b0f1d8. "
Why is it not able to empty the memory?
EDIT: Something else after the separation test is being broken down, specially crashing in S2. If you call Hepfree (_crtheap, 0, pBlock), then in some way a heap gets corrupted in the place of those lines? The Intermediate code in Mix_FreeChunk () is actually quite simple, more or less buffer is calling free (). Why would S1 be okay, but could S2 fail if this is the case?
It seems that the problem is with many piles on Windows. When I analyzed the sample code in the debugger, the SDL_mixer function Mix_FreeChunk () used free () from msvcrt.dll , While calling code malloc () with a modern Visual C runtime libraries (like msvcr110.dll or static version). It is not for this if you call SDL_malloc () , it does not matter because it is actually only #define SDL_malloc malloc Is. One solution I am looking for to use to msvcrt.dll is to use malloc () : #include & lt ; Windows.h & gt; ... typed zero * (* malloc_t) (size_t); Malloc_t msvcrt_malloc = reinterpret_cast & lt; Malloc_t & gt; (GetProcAddress (GetModuleHandle (TEXT ("msvcrt"), "molk")); ... Mix_Chunk * s2 = (Mix_Chunk *) msvcrt_malloc (Mix_Chunk); S2-> Abuf = (Uint8 *) msvcrt_malloc (s2-> Ellen * Volume (Uint8)); The program crashed for me.
Better options can only compile SDL_mixer and / or SDL libraries themselves as well as the exact same environment settings as your final application.
Comments
Post a Comment