提交 8cc5f8de 编写于 作者: J jp9000

libobs-d3d11: Don't crash if unable to rebuild shared texture

When rebuilding the graphics subsystem, it's possible a shared texture
may no longer be available.  In this case, just soft fail and allow the
texture to be rebuilt rather than crash the entire program over it.
上级 c4580ac6
......@@ -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);
......
......@@ -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()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册