microsoft / DirectXTK

The DirectX Tool Kit (aka DirectXTK) is a collection of helper classes for writing DirectX 11.x code in C++
https://walbourn.github.io/directxtk/
MIT License
2.58k stars 511 forks source link

SpriteBatch error on Xbox One #72

Closed steven-ray closed 7 years ago

steven-ray commented 7 years ago

On an Xbox One build, SpriteBatch::End() results in an exception: "GraphicsMemory singleton not created".

This appears to come from SpriteBatch::Impl::PrepareForRendering() where the following statements are present:

#if defined(_XBOX_ONE) && defined(_TITLE)
    void* grfxMemory;
    mContextResources->constantBuffer.SetData(deviceContext, transformMatrix, &grfxMemory);

In this case, SetData calls GraphicsMemory::Get().Allocate() which fails with the above exception.

My code used to work back in 11/15 with older versions of the DirectXTK. Revisiting and updating and encountering this error...

walbourn commented 7 years ago

This is by design. The January 2016 version of DirectXTK added this requirement so that the library could support Xbox One XDK apps using DirectX 11.X "Fast Semantics" as well as "Standard Semantics".

Add the GraphicsMemory singleton to your application. It's not an automatically created singleton because you must also be sure to call Commit as part of your presentation loop for proper function.

You can create a GraphicsMemory instance for PC and/or UWP as well, but it's an empty implementation so it does nothing.