Skip to content

Crash when D3D11CreateDevice fails #16

@dedmen

Description

@dedmen

See

device_.Reset();
}
// Create Enabled Blend State
D3D11_RENDER_TARGET_BLEND_DESC rt_blend_desc;
ZeroMemory(&rt_blend_desc, sizeof(rt_blend_desc));
rt_blend_desc.BlendEnable = true;
rt_blend_desc.SrcBlend = D3D11_BLEND_ONE;
rt_blend_desc.DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
rt_blend_desc.BlendOp = D3D11_BLEND_OP_ADD;
rt_blend_desc.SrcBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
rt_blend_desc.DestBlendAlpha = D3D11_BLEND_ONE;
rt_blend_desc.BlendOpAlpha = D3D11_BLEND_OP_ADD;
rt_blend_desc.RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
D3D11_BLEND_DESC blend_desc;
ZeroMemory(&blend_desc, sizeof(blend_desc));
blend_desc.AlphaToCoverageEnable = false;
blend_desc.IndependentBlendEnable = false;
blend_desc.RenderTarget[0] = rt_blend_desc;
device()->CreateBlendState(&blend_desc, blend_state_.GetAddressOf());

Device creation fails at top, device_ is null.
There is no return that aborts early.
But on L55 CreateBlendState is called, on the null device.

Also even if there were a return there, the "fallback to CPU renderer" is not working.
Failing here results in a white window.

AppCore/src/win/AppWin.cpp

Lines 107 to 128 in d3252f9

if (settings_.force_cpu_renderer) {
surface_factory_.reset(new DIBSurfaceFactory(GetDC(0)));
Platform::instance().set_surface_factory(surface_factory_.get());
} else {
#if defined(DRIVER_D3D11)
gpu_context_.reset(new GPUContextD3D11());
if (gpu_context_->device()) {
gpu_driver_.reset(new GPUDriverD3D11(gpu_context_.get()));
Platform::instance().set_gpu_driver(gpu_driver_.get());
} else {
gpu_context_.reset();
}
#elif defined(DRIVER_D3D12)
gpu_context_.reset(new GPUContextD3D12());
if (gpu_context_->Initialize()) {
gpu_driver_.reset(new GPUDriverD3D12(gpu_context_.get()));
Platform::instance().set_gpu_driver(gpu_driver_.get());
} else {
gpu_context_.reset();
}
#endif
}

When the gpu context device fails, we shall create the DIBSurfaceFactory as fallback, but we never do.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions