Reputation: 1044
I am attempting to learn 2D and 3D graphics using DirectX 11_1 and am following a number of online tutorials. However, I am using the latest VS2017 template, Direct3D UWP Game (C++/WinRT), and have been modifying example code as many of the tutorials don't apply to UWP. I successfully re-created the examples in the MSDN documentation for grid lines, and unfilled and filled rectangles. When I try to create the mountain scene in this tutorial the program crashes with the following message "Exception thrown at 0x75F9AB32 (KernelBase.dll) in Direct3D UWP Game.exe: WinRT originate error - 0x80004005 : 'Unknown exception'."
The target version for my project is 10.0.17763.0.
I have tried in the following code to render a same rectangle as I successfully created using the D2DContext FillRectangle method. The program still crashes with the same error message.
m_d2dContext->BeginDraw();
// this code draws a yellow, filled rectangle with a 100px border
//m_d2dContext->FillRectangle(
// D2D1::RectF(
// m_clientRect.left + 100.0f,
// m_clientRect.top + 100.0f,
// m_clientRect.right - 100.0f,
// m_clientRect.bottom - 100.0f),
// m_YellowBrush.Get());
// attemp to draw same rectangle using path geometries
Microsoft::WRL::ComPtr<ID2D1PathGeometry> rectGeometry;
// create empty path geometries
DX::ThrowIfFailed(m_Direct2dFactory->CreatePathGeometry(rectGeometry.GetAddressOf()));
Microsoft::WRL::ComPtr<ID2D1GeometrySink> sink = nullptr;
DX::ThrowIfFailed(rectGeometry->Open(sink.GetAddressOf()));
sink->SetFillMode(D2D1_FILL_MODE_WINDING);
sink->BeginFigure(D2D1::Point2F(m_clientRect.left + 100.0f, m_clientRect.top + 100.0f), D2D1_FIGURE_BEGIN_FILLED);
D2D1_POINT_2F points[] = {
D2D1::Point2F(m_clientRect.left + 100.0f, m_clientRect.top + 100.0f),
D2D1::Point2F(m_clientRect.right - 100.0f, m_clientRect.top + 100.0f),
D2D1::Point2F(m_clientRect.right - 100.0f, m_clientRect.bottom - 100.0f),
D2D1::Point2F(m_clientRect.left + 100.0f, m_clientRect.bottom - 100.0f),
};
sink->AddLines(points, ARRAYSIZE(points));
sink->EndFigure(D2D1_FIGURE_END_CLOSED);
DX::ThrowIfFailed(sink->Close());
m_d2dContext->DrawGeometry(rectGeometry.Get(), m_YellowBrush.Get(), 4); // draw rect
m_d2dContext->FillGeometry(rectGeometry.Get(), m_YellowBrush.Get()); // fill the rect
DX::ThrowIfFailed(m_d2dContext->EndDraw());
The error occurs when the program hits the EndDraw() line. I am fairly new to C++ programming (background is C#) but no build errors or warnings are showing.
Would appreciate any help solving this problem as I'm unable to progress any further until I understand where I'm going wrong here!!
Many thanks.
DogFather2
Upvotes: 1
Views: 330
Reputation: 3115
The error occurs when the program hits the EndDraw() line.
If EndDraw fails, it returns an HRESULT that describes any error that occurred while batching up the drawing commands. The debugger's output window may also display more information about the failure, assuming you set D2D1_DEBUG_LEVEL_INFORMATION.
Upvotes: 1