Archived

This topic is now archived and is closed to further replies.

VertexBuffer - very strange?

This topic is 5339 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

So far I have been using a vertexbuffer in global space. But now when I try to put it in my object class my application crashes upon the SetStreamSource call: pD3DDevice->SetStreamSource(0, vertexBuffer, sizeof(MY_VERTEX_STRUCT)) I find it very strange since all I did was that I removed the vertexbuffer declared in global space, and put one in my "Object" class as a public member. The variables have the same name. And they are only used by my "Object" class, which is where I create the vertexbuffer. I actually only use the vertexbuffer in three calls (all within the object class): 1. when creating the vertexbuffer. 2. when copying the vertexbuffer. 3.when setting the stream source. The object class has a Draw() function. But when I try to SetStreamSource it crashes. "Cannot read memory at..." is the errormessage. Remember that if i remove the declaration of my vertexbuffer in my Object class and put an identical in global space everything works just fine... [edited by - FxMazter on May 6, 2003 11:31:45 AM] [edited by - FxMazter on May 6, 2003 11:36:36 AM]

Share this post


Link to post
Share on other sites
Well, I might have been unclear. Here are the places I use the vertexbuffer.

1. Creating the vertexbuffer and copying the vertexinfo to it.


  
int Sprite::CreateVertexBuffer()
{
HRESULT hr;
unsigned char *vb_vertices;

hr = cGraphic.m_pD3DDevice->CreateVertexBuffer( nNumVertices*sizeof(my_vertex_struct),
D3DUSAGE_WRITEONLY,
my_vertex_struct_FVF,
D3DPOOL_MANAGED,
&vertexBuffer);
if(FAILED(hr)){
//ERROR HANDLING!

}

vertexBuffer->Lock( 0,
0,
&vb_vertices,
0);

//vertices_to_draw is global

memcpy(vb_vertices, vertices_to_draw, sizeof(vertices_to_draw) );

vertexBuffer->Unlock();

hr = D3DXCreateTextureFromFile( cGraphic.m_pD3DDevice, "DH.bmp",&g_texture);
if(FAILED(hr)){
//ERROR HANDLING!

}

return EXIT_SUCCESS;
}


2. DrawPrimitiv call:

  
int Sprite::Draw()
{

HRESULT hr;

D3DXMATRIX matWorld;
D3DXMATRIX matWorld;

cGraphic.m_pD3DDevice->SetVertexShader(my_vertex_struct_FVF);

cGraphic.m_pD3DDevice->SetTexture( 0, m_texture );

if(FAILED(cGraphic.m_pD3DDevice->SetStreamSource(0, vertexBuffer, sizeof(my_vertex_struct))))
{
//ERROR HANDLING!

}


D3DXMatrixTranslation(&transMatrix,1.5,0.0f,1.0f);
D3DXMatrixMultiply(&matWorld,&matWorld,&transMatrix);


cGraphic.m_pD3DDevice->SetTransform(D3DTS_WORLD, &matWorld);


cGraphic.m_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 12);


cGraphic.m_pD3DDevice->SetTexture(0,NULL);

return EXIT_SUCCESS;
}


Thats the only places I use the variable. And when I have it as a global, there is no problem. But when I make it as a public in the Sprite class it crashes when it comes to Draw() and to the SetStreamSource().

Can it somehow be that the vertexbuffer gets emty when CreateVertexBuffer()ends?

I dunno, plz someone help

[edited by - FxMazter on May 6, 2003 1:25:55 PM]

Share this post


Link to post
Share on other sites
I can create another vertexbuffer in global space and in the end of my CreateVertexBuffer() function i can give it the value of the vertexBuffer variable (the one I just created).

Then I can use the global vertexbuffer for SetStreamSource() and it will work OK!

So it has to be something that my original vertexbuffer mess upp somehow. But I can''t see why it would do that with those calls.

But if I give my global vertexbuffer the value of the vertexbuffer in my Sprite class, somewhere else than in my CreateVertexBuffer() function. Then it will also fail.

So, it has to be something that the vertexbuffer I create somehow fucks up in my CreateVertexBuffer(). Something that the memory is released when the function ends or something...

Does that help anyone?

Share this post


Link to post
Share on other sites
it could be on how you are using an instance of you sprite class in your main code, that it gets deleted or something. you might have to post code of the class header and how your are using it.

Share this post


Link to post
Share on other sites
Hehe

Guess what, after 4 hours meddling with this and that I gave up. I got pissed and deleated all shit and started from scratch

And guess what?

The code turned to be almost the same but this time its working. Don''t ask me what was the problem, cuz I got no clue at all.

Thx anyway

Share this post


Link to post
Share on other sites