Otherwise we may not be able to acquire a context to create the view. In practice, this is only an issue for d3d9 and earlier in combination with the Vulkan backend.
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com --- Direct3D 9 and earlier applications don't generally work with the Vulkan backend, mainly due to lack of shader model 1-3 support. Still, this may be enough for applications that only use these earlier Direct3D versions for e.g. capability queries.
dlls/wined3d/device.c | 45 ++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 24 deletions(-)
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index a400221ee30c..f61708219ac3 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -1088,6 +1088,24 @@ HRESULT wined3d_device_set_implicit_swapchain(struct wined3d_device *device, str if (device->d3d_initialized) return WINED3DERR_INVALIDCALL;
+ device->swapchain_count = 1; + if (!(device->swapchains = heap_calloc(device->swapchain_count, sizeof(*device->swapchains)))) + { + ERR("Failed to allocate swapchain array.\n"); + hr = E_OUTOFMEMORY; + goto err_out; + } + device->swapchains[0] = swapchain; + + for (i = 0; i < ARRAY_SIZE(device->state.fb.render_targets); ++i) + if (device->state.fb.render_targets[i]) + wined3d_rtv_bind_count_dec(device->state.fb.render_targets[i]); + + memset(device->state.fb.render_targets, 0, sizeof(device->state.fb.render_targets)); + if (FAILED(hr = device->adapter->adapter_ops->adapter_init_3d(device))) + goto err_out; + device->d3d_initialized = TRUE; + swapchain_desc = &swapchain->state.desc; if (swapchain_desc->backbuffer_count && swapchain_desc->backbuffer_bind_flags & WINED3D_BIND_RENDER_TARGET) { @@ -1104,28 +1122,12 @@ HRESULT wined3d_device_set_implicit_swapchain(struct wined3d_device *device, str NULL, &wined3d_null_parent_ops, &device->back_buffer_view))) { ERR("Failed to create rendertarget view, hr %#x.\n", hr); - return hr; + device->adapter->adapter_ops->adapter_uninit_3d(device); + device->d3d_initialized = FALSE; + goto err_out; } }
- device->swapchain_count = 1; - if (!(device->swapchains = heap_calloc(device->swapchain_count, sizeof(*device->swapchains)))) - { - ERR("Failed to allocate swapchain array.\n"); - hr = E_OUTOFMEMORY; - goto err_out; - } - device->swapchains[0] = swapchain; - - for (i = 0; i < ARRAY_SIZE(device->state.fb.render_targets); ++i) - if (device->state.fb.render_targets[i]) - wined3d_rtv_bind_count_dec(device->state.fb.render_targets[i]); - - memset(device->state.fb.render_targets, 0, sizeof(device->state.fb.render_targets)); - if (FAILED(hr = device->adapter->adapter_ops->adapter_init_3d(device))) - goto err_out; - device->d3d_initialized = TRUE; - device_init_swapchain_state(device, swapchain);
TRACE("All defaults now set up.\n"); @@ -1147,11 +1149,6 @@ err_out: heap_free(device->swapchains); device->swapchains = NULL; device->swapchain_count = 0; - if (device->back_buffer_view) - { - wined3d_rendertarget_view_decref(device->back_buffer_view); - device->back_buffer_view = NULL; - }
return hr; }