Fix rare race condition in overlay update code

This commit is contained in:
Cameron Gutman 2023-12-31 15:21:18 -06:00
parent 114074bfd8
commit e20d56041e
5 changed files with 15 additions and 10 deletions

View file

@ -715,7 +715,8 @@ void D3D11VARenderer::notifyOverlayUpdated(Overlay::OverlayType type)
HRESULT hr;
SDL_Surface* newSurface = Session::get()->getOverlayManager().getUpdatedOverlaySurface(type);
if (newSurface == nullptr && Session::get()->getOverlayManager().isOverlayEnabled(type)) {
bool overlayEnabled = Session::get()->getOverlayManager().isOverlayEnabled(type);
if (newSurface == nullptr && overlayEnabled) {
// The overlay is enabled and there is no new surface. Leave the old texture alone.
return;
}
@ -736,7 +737,7 @@ void D3D11VARenderer::notifyOverlayUpdated(Overlay::OverlayType type)
SAFE_COM_RELEASE(oldVertexBuffer);
// If the overlay is disabled, we're done
if (!Session::get()->getOverlayManager().isOverlayEnabled(type)) {
if (!overlayEnabled) {
SDL_FreeSurface(newSurface);
return;
}

View file

@ -844,7 +844,8 @@ void DXVA2Renderer::notifyOverlayUpdated(Overlay::OverlayType type)
HRESULT hr;
SDL_Surface* newSurface = Session::get()->getOverlayManager().getUpdatedOverlaySurface(type);
if (newSurface == nullptr && Session::get()->getOverlayManager().isOverlayEnabled(type)) {
bool overlayEnabled = Session::get()->getOverlayManager().isOverlayEnabled(type);
if (newSurface == nullptr && overlayEnabled) {
// The overlay is enabled and there is no new surface. Leave the old texture alone.
return;
}
@ -861,7 +862,7 @@ void DXVA2Renderer::notifyOverlayUpdated(Overlay::OverlayType type)
SAFE_COM_RELEASE(oldVertexBuffer);
// If the overlay is disabled, we're done
if (!Session::get()->getOverlayManager().isOverlayEnabled(type)) {
if (!overlayEnabled) {
SDL_FreeSurface(newSurface);
return;
}

View file

@ -566,7 +566,8 @@ void VAAPIRenderer::notifyOverlayUpdated(Overlay::OverlayType type)
}
SDL_Surface* newSurface = Session::get()->getOverlayManager().getUpdatedOverlaySurface(type);
if (newSurface == nullptr && Session::get()->getOverlayManager().isOverlayEnabled(type)) {
bool overlayEnabled = Session::get()->getOverlayManager().isOverlayEnabled(type);
if (newSurface == nullptr && overlayEnabled) {
// There's no updated surface and the overlay is enabled, so just leave the old surface alone.
return;
}
@ -599,7 +600,7 @@ void VAAPIRenderer::notifyOverlayUpdated(Overlay::OverlayType type)
}
}
if (!Session::get()->getOverlayManager().isOverlayEnabled(type)) {
if (!overlayEnabled) {
SDL_FreeSurface(newSurface);
return;
}

View file

@ -333,7 +333,8 @@ void VDPAURenderer::notifyOverlayUpdated(Overlay::OverlayType type)
VdpStatus status;
SDL_Surface* newSurface = Session::get()->getOverlayManager().getUpdatedOverlaySurface(type);
if (newSurface == nullptr && Session::get()->getOverlayManager().isOverlayEnabled(type)) {
bool overlayEnabled = Session::get()->getOverlayManager().isOverlayEnabled(type);
if (newSurface == nullptr && overlayEnabled) {
// There's no updated surface and the overlay is enabled, so just leave the old surface alone.
return;
}
@ -358,7 +359,7 @@ void VDPAURenderer::notifyOverlayUpdated(Overlay::OverlayType type)
}
}
if (!Session::get()->getOverlayManager().isOverlayEnabled(type)) {
if (!overlayEnabled) {
SDL_FreeSurface(newSurface);
return;
}

View file

@ -181,7 +181,8 @@ void SLVideoDecoder::notifyOverlayUpdated(Overlay::OverlayType type)
}
SDL_Surface* newSurface = Session::get()->getOverlayManager().getUpdatedOverlaySurface(type);
if (newSurface == nullptr && Session::get()->getOverlayManager().isOverlayEnabled(type)) {
bool overlayEnabled = Session::get()->getOverlayManager().isOverlayEnabled(type);
if (newSurface == nullptr && overlayEnabled) {
// There's no updated surface and the overlay is enabled, so just leave the old surface alone.
return;
}
@ -193,7 +194,7 @@ void SLVideoDecoder::notifyOverlayUpdated(Overlay::OverlayType type)
m_Overlay = nullptr;
}
if (!Session::get()->getOverlayManager().isOverlayEnabled(type)) {
if (!overlayEnabled) {
SDL_FreeSurface(newSurface);
return;
}