This project has moved and is read-only. For the latest updates, please go here.

AccessViolationException while creating SpriteBatch

May 15, 2013 at 9:42 AM
Edited May 15, 2013 at 9:43 AM

if I try to create a new SpriteBatch, I get an AccessViolationException on (MainPage.xaml)
Code to init SpriteBatch (CubeRenderer.cpp in CreateDeviceResources()):
m_spriteBatch = unique_ptr<SpriteBatch>(new SpriteBatch(m_d3dContext.Get()));
As Project Template I use the default Windows Phone Direct3D with XAML Tempalte of the Windows Phone 8 SDK and I modify the CubeRenderer basic class. Does anyone know this issue?
May 15, 2013 at 6:07 PM
Usually I've found this will happen when you've got a bad pointer (perhaps you deleted it somewhere or it was never initialized?). I'd need more information (a stack trace would be handy here) to help you figure out what the cause was. If it's happening when you create your SpriteBatch object, I'd bet your m_d3dContext pointer is bad.
May 15, 2013 at 7:03 PM

I don't get an StackTrace. The Problem i think is here the mixed C++ and C# Code. The WP8 Project is written in C# and includes the C++ Library. I only get the ArgumentViolationException. I also do not think the m_d3dContext is bad, because if I remove the SpriteBatch initialization, all other code (including Context Methods) work fine.

I use the Standard Default Template of Visual Studio and only added the DirectX Tool Kit.
May 16, 2013 at 9:26 PM
I imagine that's because the interop hasn't completed initializing yet. Put it in CubeRenderer::CreateWindowSizeDependentResources() instead, or somewhere else.
May 17, 2013 at 7:12 AM

that's it. Works all fine now. Thanks!
Marked as answer by walbourn on 1/23/2014 at 11:27 PM