Skip to main content
GameDev.net gamedev.net
🔒 Locked

Locking a Dynamic Array

Started by Carradine Apr 10, 2005 at 3:33 PM 0 replies 700+ views
Original Post
Carradine
Carradine
I am sure this has a simple answer, but I cannot find it. I am just trying to figure out how to lock vertex information into the vertex buffer with data created with a new/delete array. Using the Direct3D tutorial #2 as an example, I realize that this works: CUSTOMVERTEX pVertices[3]; pVertices[0].color = 0xffff0000; pVertices[0].rhw = 1.0f; pVertices[0].x = 150.0f; pVertices[0].y = 50.0f; pVertices[0].z = 0.5f; pVertices[1].color = 0xff00ff00; pVertices[1].rhw = 1.0f; pVertices[1].x = 250.0f; pVertices[1].y = 250.0f; pVertices[1].z = 0.5f; pVertices[2].color = 0xff00ffff; pVertices[2].rhw = 1.0f; pVertices[2].x = 50.0f; pVertices[2].y = 250.0f; pVertices[2].z = 0.5f; VOID * vertices; if( FAILED( g_pVB->Lock( 0,0, &vertices, 0 ) ) ) return E_FAIL; memcpy( vertices, pVertices, sizeof(pVertices) ); g_pVB->Unlock(); However if I attempt to use this to store my vertices: CUSTOMVERTEX pVertices[3]; pVertices = new CUSTOMVERTEX[3]; //vert info lock, memcpy, unlock delete pVertices; The information is not copied correctly, and nothing appears on the screen. I have tried to look through a great deal of exmaples, but no one uses this storage format to store vertex data. Is it even possible?
--------------------------Vantage: Greenlit on Steam / Independent Games Festival Submission http://www.crystaldragon.com
shrtysk8r1
shrtysk8r1
First of all, you are wasting memory - change CUSTOMVERTEX pVertices[3] to CUSTOMVERTEX* pVertices. That is most likely your problem, as a pointer to a statically allocated array cannot be changed to point to heap memory.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.