Primitive Vector (Direct3D)

The problem happens when this is executed:
primitive_vector.push_back(new_primitive);

With the constructor here:
primitive(unsigned int verts)
{
vertices = 0;
P->CreateVertexBuffer(verts * sizeof(Vertex),D3DUSAGE_WRITEONLY,FVF_VERTEX,D3DPOOL_MANAGED,&VB,0);
VB->Lock(0, 0, (void**)&vertex, 0);
}

When I am trying to add a new primitive to the vector container "primitive_vector".

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Vertex structure
struct Vertex
{
	Vertex(float x, float y, float z, float nx, float ny, float nz, float u, float v)
	{
		_x  = x;  _y  = y;  _z  = z;
		_nx = nx; _ny = ny; _nz = nz;
		_u  = u;  _v  = v;
	}
    float _x, _y, _z;
    float _nx, _ny, _nz;
    float _u, _v;
};
#define FVF_VERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1)

// Primitive class
class primitive
{
private:
	unsigned int vertices;
	IDirect3DVertexBuffer9* VB;
	IDirect3DDevice9* P;
	Vertex* vertex;
public:
	primitive(unsigned int verts)
	{
		vertices = 0;
		P->CreateVertexBuffer(verts * sizeof(Vertex),D3DUSAGE_WRITEONLY,FVF_VERTEX,D3DPOOL_MANAGED,&VB,0);
		VB->Lock(0, 0, (void**)&vertex, 0);
	}
	void stop()
	{	
		VB->Unlock();
	}
	void add(float x, float y, float z, float nx, float ny, float nz, float tx, float ty)
	{
		vertex[vertices] = Vertex(x,y,z,nx,ny,nz,tx,ty);
		vertices++;
	}
	void draw()
	{
		P->DrawPrimitive(D3DPT_TRIANGLELIST,0,vertices-1);
	}
};

std::vector<primitive> primitive_vector;

// Primitives
int begin_primitive(unsigned int verts)
{
	primitive new_primitive(verts);
	primitive_vector.push_back(new_primitive);
	primitives++;
	return (primitives-1);
}

void add_vertex(int i, float x, float y, float z)
{
	primitive_vector[i].add(x,y,z,0,0,0,0,0);
}

void end_primitive(int i)
{
	primitive_vector[i].stop();
}

void draw_primitive(int i)
{
	primitive_vector[i].draw();
}
Last edited on
What's the error/bug?
Everything there:
1
2
3
vertices = 0;
		P->CreateVertexBuffer(verts * sizeof(Vertex),D3DUSAGE_WRITEONLY,FVF_VERTEX,D3DPOOL_MANAGED,&VB,0);
		VB->Lock(0, 0, (void**)&vertex, 0);


All the pointers and variables equal some weird expression like 0xcccccccc.
Do you ever set the pointers to anything valid?
Topic archived. No new replies allowed.