Error with my directX program

OK I've run into a new error, I did fix all my program before (it didn't draw but it didn't break either haha), the error I get is either an access writing location violation error or a variable is used but not initialised, here is the code:

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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef MODELOBJECT_H
#define MODELOBJECT_H

#include <windows.h>
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <d3d9.h>
#include <d3dx9.h>
#include <string>
#include "structures.h"

void getModel();

using namespace std;

class modelObject
{
public:
	D3DXVECTOR3 position;
	CUSTOMVERTEX* vertices;
	short* indices;
	int numVertices;
	int numFaces;
	IDirect3DTexture9* mFaceTex;

private:
	LPDIRECT3DDEVICE9 d3ddev;
	IDirect3DVertexBuffer9* vBuffer;
	IDirect3DIndexBuffer9* iBuffer;
	char* fileName;
	char* textureName;
	int numV;
	int numVT;
	int numVN;
	int numF;

        void getModel()
        {
                //rather lengthy file reading function, no errors here as I've tested multiple times, removed for ease of reading
        }

	void initialiseBuffer()
	{
		d3ddev->CreateVertexBuffer(numVertices*sizeof(CUSTOMVERTEX), 0, 0, D3DPOOL_MANAGED, &vBuffer, NULL);
		VOID* pVoid;
		vBuffer->Lock(0, 0, (void**)pVoid, 0);
		memcpy(pVoid, vertices, sizeof(vertices));
		vBuffer->Unlock();
		
		d3ddev->CreateIndexBuffer(numVertices*sizeof(short), 0, D3DFMT_INDEX16, D3DPOOL_MANAGED, &iBuffer, NULL);
		iBuffer->Lock(0, 0, (void**)iBuffer, 0);
		memcpy(pVoid, indices, sizeof(indices));
		iBuffer->Unlock();
	}

public:
	modelObject(LPDIRECT3DDEVICE9 dev)
	{
		d3ddev = dev;
		numVertices = 0;
		numFaces = 0;
		numV = 0;
		numVT = 0;
		numVN = 0;
		numF = 0;
	}

	modelObject(LPDIRECT3DDEVICE9 dev, D3DXVECTOR3 pos, char* fN, char* tN)
	{
		d3ddev = dev;
		numVertices = 0;
		numFaces = 0;
		numV = 0;
		numVT = 0;
		numVN = 0;
		numF = 0;
		position = pos;
		fileName = fN;
		D3DXCreateTextureFromFile(d3ddev, tN, &mFaceTex);
		getModel();
	}

	~modelObject()
	{
		vBuffer->Release();
		iBuffer->Release();
		delete [] vertices;
		delete [] indices;
	}

	void draw()
	{
		d3ddev->SetStreamSource(0, vBuffer, 0, sizeof(CUSTOMVERTEX));
		d3ddev->SetIndices(iBuffer);

		d3ddev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, numVertices, 0, numFaces);
	}
};

#endif 


problematic code in bold and italic, I get the writing violation error thing when I have that line as VOID* pVoid = NULL; and the uninitialised variable as it is now, I haven't a clue how to fix it and honestly, this is the code my tutor supplied and it did work, I've just moved it into this class to make it more modular

any help is very much appreciated :)
i'm sure you should be passing it like this:

vBuffer->Lock(0, 0, (void**)&pVoid, 0);

note the pVoid changed to &pVoid
I don't think this would make the memory for iBuffer very happy..

iBuffer->Lock(0, 0, (void**)iBuffer, 0);
Thanks so much kaije :), that happened to be the problem, this is kinda why i wanna stick to openGL, makes sense ot me :P

and moooce... that was intentional, as a test to you gurus... ¬_¬ :) thanks haha, i did fix that once before, seems i loaded an older version this time around to work on haha :)

my program still doesnt draw but it doesnt break which is kinda nice :)
Topic archived. No new replies allowed.