openframeworks / openFrameworks

openFrameworks is a community-developed cross platform toolkit for creative coding in C++.
http://openframeworks.cc
Other
9.83k stars 2.56k forks source link

ofVideoPlayer is crashing when setVolume is called on update() #8024

Closed Vamoss closed 1 week ago

Vamoss commented 1 week ago

I am on VS 2019 with OF 0.12.0 in Windows 11. The ofVideoPlayer craches the software specially when I try to set an audio fade during the update using video.setVolume(value).

  stack --
  ntdll.dll!00007ff8ad4e1eef() Unknown
  (...) (...)
  ucrtbased.dll!00007ff82a3049c5() Unknown
  VideoPlayer_debug.exe!operator delete(void * block) Line 38 C++
  VideoPlayer_debug.exe!operator delete(void * block, unsigned int64 formal) Line 32 C++
  VideoPlayer_debug.exe!ofMediaFoundationUtils::AsyncCallback::`scalar deleting destructor’(unsigned int) C++
VideoPlayer_debug.exe!ofMediaFoundationUtils::AsyncCallback::Release() Line 67 C++

@NickHardeman proposed this solution here on ofMediaFoundationPlayer:

//----------------------------------------------
void ofMediaFoundationPlayer::setVolume(float volume) {
    if (m_spMediaEngine) {
        double cvolume = ofClamp(volume, 0.0f, 1.0f);
        HRESULT hr = m_spMediaEngine->SetVolume(cvolume);
        if (hr != S_OK) {
            ofLogVerbose("ofMediaFoundationPlayer :: setVolume : Unable to set volume to ") << volume << ".";
        }
        //ofMediaFoundationUtils::CallAsyncBlocking(
            //[&] {m_spMediaEngine->SetVolume(static_cast<double>(volume));
            //[&] {m_spMediaEngine->SetVolume(cvolume);
        //});
    }
}
NickHardeman commented 1 week ago

Hi @Vamoss, Thank you for posting this here. It appeared to fix the issue for me for a simple test case. Were you able to test the proposed fix?

Vamoss commented 1 week ago

Hi @NickHardeman, I just tested it. It seems to have fixed the issue, the software is not crashing anymore 🥳 Thank you!