Resizing behavior of using IDXGISwapChain1::ResizeBuffer() is weird

thebluetropics
1,046
Reputation points
I have building a Direct2D 1.1 application, and now I currently learn how to handle the WM_SIZE, but something weird occurs:
Resize window code:
case WM_SIZE: {
UINT w = LOWORD(lparam);
UINT h = HIWORD(lparam);
win->Resize(w, h);
return 0;
}
void MainWindow::Resize(UINT nwidth, UINT nheight) {
if (state.dxgiSwapChain) {
HRESULT hresult;
state.d2dDeviceContext->SetTarget(nullptr);
SafeRelease(&state.dxgiBackBuffer);
hresult = state.dxgiSwapChain->ResizeBuffers(
2,
nwidth,
nheight,
DXGI_FORMAT_B8G8R8A8_UNORM,
0
);
if (FAILED(hresult)) {
if (hresult == DXGI_ERROR_DEVICE_REMOVED) {
OutputDebugStringW(L"DXGI Device Removed\n");
} else if (hresult == DXGI_ERROR_DEVICE_RESET) {
OutputDebugStringW(L"DXGI Device Reset\n");
} else {
OutputDebugStringW(L"Any else\n");
}
}
IDXGISurface* s_dxgiBackBuffer;
FLOAT dpi = GetDpiForWindow(state.hwnd);
D2D1_BITMAP_PROPERTIES1 bitmapProperties = D2D1::BitmapProperties1(
D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW,
D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE),
dpi,
dpi,
NULL
);
if (FAILED(state.dxgiSwapChain->GetBuffer(
0,
IID_PPV_ARGS(&s_dxgiBackBuffer)
))) throw std::runtime_error("Failed to get buffer\n");
if (FAILED(state.d2dDeviceContext->CreateBitmapFromDxgiSurface(
s_dxgiBackBuffer,
bitmapProperties,
&state.dxgiBackBuffer
))) throw std::runtime_error("Failed create bitmap\n");
state.d2dDeviceContext->SetTarget(state.dxgiBackBuffer);
}
}
{count} votes
@Jeanine Zhang-MSFT
I have released the the
ID2D1Bitmap1
before I callResizeBuffer()
, what else I should release?I suggest you could refer to he Doc: Care and feeding of the swap chain and Handling window resizing
What does hresult return for ResizeBuffers ?
If it returns S_OK, the problem is in the Paint event
I see. let me check for it.
@thebluetropics
May I know if the issue has been solved? I am glad to help if you have any other question.
This is indeed, the problem is still not found, but I have another better approach, thanks for the help anyway, @Jeanine Zhang-MSFT
Sign in to comment