내 모델 변수 정점 배열과 정점 버퍼를 저장하는 간단한 클래스를 만들려고합니다. 그래서 나는 객체를 동적으로 생성하고 관리하기 위해 myclass 배열을 생성한다. 하지만 언제ID3D11Buffer로 인해 액세스 위반이 발생했습니다.
hr = g_pd3dDevice->CreateBuffer(&bd, &InitData, &pieces[counter].g_pVertexBuffer);
이 라인 실행 "Access violation reading location"오류가 발생합니다. 나는 많은 것을 시도하지만 결코 성공하지 못합니다. 클래스 및 배열을 사용하지 않으면이 오류가 발생하지 않습니다. Porgram은 오류없이 실행됩니다.
MyClass에 : MyClass에의
class Piece
{
public:
double positionX, positionZ,
red, green,blue;
bool renderable;
int type, color, vertexCount;
XMMATRIX g_WorldPieces;
ID3D11Buffer* g_pVertexBuffer;
SimpleVertex* vertices;
Piece();
void create(int, int, double, double);
};
Piece::Piece()
{
g_pVertexBuffer = NULL;
}
void Piece::create(int t, int c, double pX, double pZ)
{
g_pVertexBuffer = NULL;
renderable = true;
type = t;
color = c;
red=green=blue=0.0f;
if(color == 1)
red=green=blue=1.0f;
positionX = pX;
positionZ = pZ;
vertexCount = 0;
}
Piece *pieces;//Global variable which define after defining "ID3D11Device* g_pd3dDevice = NULL"
및 사용하여 객체 :
for(int x=0;x<4;x++)
{
if(x==2)
{
c=0;
positionZ = 12.5;
}
for(int y=0;y<8;y++)
{
pieces[counter].create(typeArray[x][y],c,positionX,positionZ);
positionX += 5;
switch(pieces[counter].type)
{
//Switching object txt. All cases and breaks are fine.
}
fin >> pieces[counter].vertexCount;
pieces[counter].vertices = new SimpleVertex[vertexCount];
for(int i=0; i<vertexCountpiyon; i++)
{
fin >> pieces[counter].vertices[i].Pos.x >> pieces[counter].vertices[i].Pos.y >> pieces[counter].vertices[i].Pos.z;
fin >> pieces[counter].vertices[i].Tex.x >> pieces[counter].vertices[i].Tex.y;
fin >> pieces[counter].vertices[i].Normal.x >> pieces[counter].vertices[i].Normal.y >> pieces[counter].vertices[i].Normal.z;
}
fin.close();
bd.ByteWidth = sizeof(SimpleVertex) *pieces[counter].vertexCount;
ZeroMemory(&InitData, sizeof(InitData));
InitData.pSysMem = pieces[counter].vertices;
hr = g_pd3dDevice->CreateBuffer(&bd, &InitData, &pieces[counter].g_pVertexBuffer);//THIS LINE IS MY PROBLEM!
if(FAILED(hr)) return hr;
counter++;
}
positionX = -17.5;
positionZ += 5;
}
나는 액세스 위반 카운터 내 프로젝트의 0
소스 코드 얻을 때 : http://1drv.ms/1nKdoUf
'bd','InitData' 및'g_pVertexBuffer'의 세 변수 중 어느 것이 문제를 일으키는 지 추측 할 수 있었습니까? 나는'g_pd3dDevice'가 인스턴스로 설정되어 있다고 가정합니까? – MicroVirus
이 변수 g_pVertexBuffer를 사용하면 클래스의 객체 배열을 사용할 때 문제가 발생합니다. 모든 모델에 간단한 varable을 사용하면 오류가 발생하지 않습니다. –