Jump to content
  • Advertisement
Sign in to follow this  
Ratslayer

Null pointer exception during primitives draw call.

This topic is 2264 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. I am having a null pointer exception when I call ID3D10Device::Draw(int,int) in my render function. This is the code:

//CONSTRUCTOR

CSprite::CSprite(Dx10Manager *pman, CTexture *pt, Vec2 pos, Vec2 scale, float depth)
: IDrawable(pman),
Pos(pos),
Scale(scale),
Depth(depth),
pVertexBuffer(NULL)
{
pTexture=pt;
Size=pTexture?pTexture->GetSize():Vec2();
SpriteVertex *pVertex=new SpriteVertex();

D3D10_BUFFER_DESC bd;
bd.Usage = D3D10_USAGE_DYNAMIC;
bd.ByteWidth = sizeof( SpriteVertex );
bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
bd.MiscFlags = 0;

D3D10_SUBRESOURCE_DATA sd;
sd.pSysMem=pVertex;

if(FAILED(pManager->GetDevice()->CreateBuffer(&bd, &sd, &pVertexBuffer)))
{
_log<<L"Could not create a vertex buffer."<<endl;
}
delete pVertex;
}
//RENDER FUNCTION
void CSprite::Draw()
{
if(pVertexBuffer)
{
UINT stride = sizeof( SpriteVertex );
UINT offset = 0;
ID3D10Device *device=pManager->GetDevice();
device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);
device->IASetVertexBuffers(0, 1, &pVertexBuffer, &stride, &offset);
device->Draw(1,0);
}
}


I am not exactly sure what I am doing wrong. The pVertexBuffer pointer seems fine, so is the device pointer. Does anyone know what could be up? Thank you for your time.

Share this post


Link to post
Share on other sites
Advertisement
You know what the problem is. The `device` variable is NULL and you are calling draw on it. Step through your code to find why the device is NULL. If you use visual studio, use the call stack.

Share this post


Link to post
Share on other sites
No, the device pointer is not null. I guess I didn't specify that I have checked it, but it wouldn't make sense, because the error would fire at the calls of IASetVertexBuffers or IASetPrimitiveTopology, since the device pointer is not modified.
The Call Stack tells me that the error originates from "d3d10core.dll!NMultithread::CDevice::Draw() + 0x3a bytes", which is why I can not debug it through regular ways. I am doing something wrong; feeding the device some bad data, which is why it crashes. But I have no idea why.

Share this post


Link to post
Share on other sites
specify D3D10_CREATE_DEVICE_DEBUG when creating the device and check if anything suspicious pops up prior to the crash

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!