DirectXTK Sprites Init Crash

Started by
3 comments, last by kubera 8 years, 2 months ago

Hello guys! This is my first post here because I'm desperated to fix this error. My renderer is DX11 and I've already included all headers and the DirectXTK.lib so the problem is when my program reachs this code in runtime 6a5cf6e1439f7facb5d8b192510daad9.png

https://gyazo.com/6a5cf6e1439f7facb5d8b192510daad9

where pSpriteBatch is defined like this:


std::unique_ptr<SpriteBatch> pSpriteBatch;

This is the DXInitializer:


void DX11Renderer::InitDevice()
{
DXGI_SWAP_CHAIN_DESC scd;
 
ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC));
scd.BufferCount = 1;  
scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
scd.BufferDesc.Width = ScreenX;
scd.BufferDesc.Height = ScreenY;
scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
scd.OutputWindow = DXWindow;
scd.SampleDesc.Count = 4;
scd.Windowed = TRUE;
scd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
 
///DEVICE INIT
D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, NULL, NULL, D3D11_SDK_VERSION, &scd, &DX11SwapChain, &DX11Device, NULL, &DX11DeviceContext);
 
DX11SwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&BackBuffer);
 
DX11Device->CreateRenderTargetView(BackBuffer, NULL, &DX11RenderTargetView);
BackBuffer->Release();
 
DX11DeviceContext->OMSetRenderTargets(1, &DX11RenderTargetView, NULL);
 
///VIEWPORT INIT
D3D11_VIEWPORT viewport;
ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT));
 
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
viewport.Width = ScreenX;
viewport.Height = ScreenY;
 
DX11DeviceContext->RSSetViewports(1, &viewport);
 
///FONTS INIT
pSpriteBatch.reset(new SpriteBatch(DX11DeviceContext)); // <<-- crash
pPurista12.reset(new SpriteFont(DX11Device, L"font.spritefont"));
 
///BUFFER INIT
D3D11_BUFFER_DESC bd;
ZeroMemory(&bd, sizeof(bd));
 
bd.Usage = D3D11_USAGE_DYNAMIC;
bd.ByteWidth = sizeof(VERTEX) * 30;
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
 
DX11Device->CreateBuffer(&bd, NULL, &VertexBuffer);
 
///BLEND INIT
 
///SHADER INIT
InitRenderShaders();
}

When it reachs the line it shows me this exception 02589a97c1d19a0e5a02aaae9103ecd1.png

https://gyazo.com/02589a97c1d19a0e5a02aaae9103ecd1

and this is the breakpoint details 5aca89f56827d44d5a938b412aef40f9.png

https://gyazo.com/5aca89f56827d44d5a938b412aef40f9

To be specific, the code will crash when it reachs this code from the file 'mutex.c':

5a320b954b101b87e97fa7623913ad1a.png
https://gyazo.com/5a320b954b101b87e97fa7623913ad1a

Does anybody any idea why this happens? I'm building it as Release in x64 bits.

Thanks in advance.

Advertisement
It looks like it's crashing because the "mtx" pointer is NULL. You can tell this because the exceptions specifies that it's trying to load something at address 0x0000000000000010, which suggests that the "type" member of _Mtx_t is located 16 bytes from the start of the class/struct.

Could you post the callstack, so that we can see who is trying to lock a mutex?

> msvcp120.dll!mtx_do_lock(_Mtx_internal_imp_t * * mtx, const xtime * target) Line 49 C++
  DirectX 11 Overlay.exe!DirectX::SharedResourcePool<struct ID3D11Device *,struct DirectX::SpriteBatch::Impl::DeviceResources>::DemandCreate(struct ID3D11Device *) Unknown
  DirectX 11 Overlay.exe!DirectX::SpriteBatch::Impl::Impl(struct ID3D11DeviceContext *) Unknown
  DirectX 11 Overlay.exe!DirectX::SpriteBatch::SpriteBatch(struct ID3D11DeviceContext *) Unknown
  DirectX 11 Overlay.exe!DX11Renderer::InitDevice() Line 133 C++
  DirectX 11 Overlay.exe!DX11Renderer::InitWindow() Line 73 C++
  DirectX 11 Overlay.exe!main() Line 8 C++
  [External Code] 

c0d96f86e7afe8daacb092ae2b48e165.png
https://gyazo.com/c0d96f86e7afe8daacb092ae2b48e165

anybody?

Yoy may post the question on the GitHub.

https://github.com/Microsoft/DirectXTK

This topic is closed to new replies.

Advertisement