diff --git a/libobs-d3d11/d3d11-rebuild.cpp b/libobs-d3d11/d3d11-rebuild.cpp index effaff844..c0b1c1315 100644 --- a/libobs-d3d11/d3d11-rebuild.cpp +++ b/libobs-d3d11/d3d11-rebuild.cpp @@ -31,15 +31,43 @@ inline void gs_index_buffer::Rebuild(ID3D11Device *dev) throw HRError("Failed to create buffer", hr); } +void gs_texture_2d::RebuildSharedTextureFallback() +{ + td = {}; + td.Width = 2; + td.Height = 2; + td.MipLevels = 1; + td.Format = DXGI_FORMAT_B8G8R8A8_UNORM; + td.ArraySize = 1; + td.SampleDesc.Count = 1; + + width = td.Width; + height = td.Height; + dxgiFormat = td.Format; + levels = 1; + + resourceDesc = {}; + resourceDesc.Format = td.Format; + resourceDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + resourceDesc.Texture2D.MipLevels = 1; + + isShared = false; +} + inline void gs_texture_2d::Rebuild(ID3D11Device *dev) { HRESULT hr; if (isShared) { hr = dev->OpenSharedResource((HANDLE)(uintptr_t)sharedHandle, __uuidof(ID3D11Texture2D), (void**)&texture); - if (FAILED(hr)) - throw HRError("Failed to open shared 2D texture", hr); - } else { + if (FAILED(hr)) { + blog(LOG_WARNING, "Failed to rebuild shared texture: ", + "0x%08lX", hr); + RebuildSharedTextureFallback(); + } + } + + if (!isShared) { hr = dev->CreateTexture2D(&td, data.size() ? srd.data() : nullptr, &texture); diff --git a/libobs-d3d11/d3d11-subsystem.hpp b/libobs-d3d11/d3d11-subsystem.hpp index 237fdc8d2..1cec188cb 100644 --- a/libobs-d3d11/d3d11-subsystem.hpp +++ b/libobs-d3d11/d3d11-subsystem.hpp @@ -362,6 +362,7 @@ struct gs_texture_2d : gs_texture { void InitRenderTargets(); void BackupTexture(const uint8_t **data); + void RebuildSharedTextureFallback(); inline void Rebuild(ID3D11Device *dev); inline void Release()