FNA-XNA / FAudio

FAudio - Accuracy-focused XAudio reimplementation for open platforms
https://fna-xna.github.io/
Other
534 stars 72 forks source link

Running into a segmentation fault #332

Closed ZachBacon closed 4 months ago

ZachBacon commented 4 months ago

I've been working on implementing FAudio into my project. But I've been running into this one particular issue where I have

class FAudio_BufferNotify : public FAudioVoiceCallback {
public:
    HANDLE hBufferEndEvent;

    FAudio_BufferNotify()
    {
        hBufferEndEvent = NULL;
        hBufferEndEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
        assert(hBufferEndEvent != NULL);
    }

    ~FAudio_BufferNotify()
    {
        CloseHandle(hBufferEndEvent);
        hBufferEndEvent = NULL;
    }

    // dummies:
    void OnBufferEnd(void * pBufferContext){
        assert(hBufferEndEvent != NULL);
        SetEvent(hBufferEndEvent);
    }
    void OnVoiceProcessingPassStart(uint32_t BytesRequired) {}
    void OnVoiceProcessingPassEnd() {}
    void OnStreamEnd() {}    
    void OnBufferStart(void * pBufferContext) {}
    void OnLoopEnd(void * pBufferContext) {}
    void OnVoiceError(void * pBufferContext, uint32_t Error) {}
};

But while it compiles, it seems to run into an issue regarding OnVoiceProcessingPassStart seems to choke up, but if I leave it as a com call using STDMETHOD it seems to run fine

I compiled FAudio in debug mode and lldb gives this


* thread #8, stop reason = Exception 0xc0000005 encountered at address 0x7ff662e3e8dc: Access violation reading location 0xffffffffffffffff
    frame #0: 0x00007ff662e3e8dc visualboyadvance-m.exe`FAudio_INTERNAL_MixSource(voice=0x0000020ff6b3f790) at FAudio_internal.c:829:3
   826                  FAudio_PlatformUnlockMutex(voice->audio->sourceLock);
   827                  LOG_MUTEX_UNLOCK(voice->audio, voice->audio->sourceLock)
   828
-> 829                  voice->src.callback->OnVoiceProcessingPassStart(
   830                          voice->src.callback,
   831                          FAudio_INTERNAL_GetBytesRequested(voice, (uint32_t) toDecode)
   832                  );
(lldb) bt
* thread #8, stop reason = Exception 0xc0000005 encountered at address 0x7ff662e3e8dc: Access violation reading location 0xffffffffffffffff
  * frame #0: 0x00007ff662e3e8dc visualboyadvance-m.exe`FAudio_INTERNAL_MixSource(voice=0x0000020ff6b3f790) at FAudio_internal.c:829:3
    frame #1: 0x00007ff662e3c227 visualboyadvance-m.exe`FAudio_INTERNAL_GenerateOutput(audio=0x0000020ff6b22540, output=0x0000020ff6b370c0) at FAudio_internal.c:1337:4
    frame #2: 0x00007ff662e3bea7 visualboyadvance-m.exe`FAudio_INTERNAL_UpdateEngine(audio=0x0000020ff6b22540, output=0x0000020ff6b370c0) at FAudio_internal.c:1435:3
    frame #3: 0x00007ff662e420fc visualboyadvance-m.exe`FAudio_INTERNAL_MixCallback(userdata=0x0000020ff6b22540, stream="", len=3840) at FAudio_platform_sdl2.c:46:3
    frame #4: 0x00007ff662d815fd visualboyadvance-m.exe`SDL_RunAudio + 317
    frame #5: 0x00007ff662d74539 visualboyadvance-m.exe`SDL_RunThread + 41
    frame #6: 0x00007ff662dc480e visualboyadvance-m.exe`RunThreadViaCreateThread + 14
    frame #7: 0x00007ff98687257d kernel32.dll`BaseThreadInitThunk + 29
    frame #8: 0x00007ff98866aa58 ntdll.dll`RtlUserThreadStart + 40

Now I'm not much of a c/c++ developer, and I do apologize for the ignorance and lack of understanding. But from what I've read what I have should in theory work. But I can't help but think I'm missing something.

ZachBacon commented 4 months ago

After bouncing around some ideas and asking questions, I finally understand that I needed a way to pass pointers from the FAudioVoiceCallback into the class I am using. Seems to be working now that I reworked my issue.