すいません、解決したと思って色々と拡張していたのですが、Releaseビルドしたところアクセス違反になってしまいました。。。
>このプログラムはデフォルト設定なのでVSYNCを待つ状態で動作します。
言われてみれば不要なSleepでした、ご指摘ありがとうございます(GetNowCountのテストをしていたときの名残です)
あれからより多くのモデルを描写できるよう拡張していたのですが、Releaseビルドで一定の頂点数を超えて描写するとアクセス違反になってしまいます。
プログラムは DrawPolygonIndexed3DToShader で停止し、引数にしていた DrawVertexNum と DrawIndexNum の数値がおかしかったので
これが原因なのかな? と思い直前にブレークポイントを差しましたが、変わらず DrawPolygonIndexed3DToShader でアクセス違反になってしまいました。
また、アクセス違反にならずとも一定の頂点数を超えると描写が乱れてしまいます。
いずれも Debugビルドや DrawPolygonIndexed3D では正しく表示されています。
DrawPolygonIndexed3DToShader の使い方が悪いのでしょうか? どなたかご教授おねがいします。
DXライブラリのVerは3.20a、
シェーダーとモデルはサンプルプログラム「剛体メッシュのライティング無し描画」の物に加え、
前レスの通り改変したもの(VertexShader.vso)を使用しています。
エラー文
0x67074754 (igdumdim32.dll) で例外がスローされました (getnowcount.exe 内): 0xC0000005: 場所 0x01B00000 の読み取り中にアクセス違反が発生しました
以下プログラム
#include "DxLib.h"
#define WORD_MAX 65535
#define DRAW_VERTEX_MAX 24*3*5*5
#define MODEL_SIZE 256.0f
int GameTime=0;
// プログラムは WinMain から始まります
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
//
ChangeWindowMode(TRUE);
SetUseDirect3DVersion(DX_DIRECT3D_9EX);
if (DxLib_Init()==-1) return -1;
SetDrawScreen(DX_SCREEN_BACK);
//
int VertexShaderHandle = LoadVertexShader("VertexShader.vso");
int MV1VertexShaderHandle = LoadVertexShader("NormalMesh_NoLightVS.vso");
int PixelShaderHandle = LoadPixelShader("NormalMesh_NoLightPS.pso");
int ModelHandle = MV1LoadModel("NormalBox.mqo");
int TextureHandle = MV1GetTextureGraphHandle(ModelHandle,0);
//
MV1SetupReferenceMesh(ModelHandle, -1,TRUE);
//
//MV1SetUseOrigShader(TRUE);
//
//SetUseVertexShader(VertexShaderHandle);
//SetUsePixelShader(PixelShaderHandle);
SetUseTextureToShader(0,TextureHandle);
//
SetUseBackCulling(TRUE);
SetUseZBuffer3D(TRUE);
SetWriteZBuffer3D(TRUE);
SetUseLighting(FALSE);
SetLightEnable(FALSE);
SetUseNormalDrawShader(FALSE);
//
SetCameraPositionAndTarget_UpVecY({320.0f,240.0f+MODEL_SIZE,MODEL_SIZE*-10.0f},{320.0f,240.0f,0.0f});
SetCameraNearFar(MODEL_SIZE*0.1f,MODEL_SIZE*20);
SetBackgroundColor(40,50,70);
//テスト用
VERTEX3DSHADER DrawVertexToShader[DRAW_VERTEX_MAX];
VERTEX3D DrawVertex[DRAW_VERTEX_MAX];
unsigned short DrawIndex[DRAW_VERTEX_MAX];
int DrawVertexNum,DrawPolygonNum,DrawIndexNum;
int ZKey = 0;
int XKey = 0;
int CKey = 0;
int RightKey = 0;
int LeftKey = 0;
int UpKey = 0;
int DownKey = 0;
int XZ_Max=1;
int Y_Max=1;
char Shader=0;
bool Index=0;
bool SetPos=1;
int msave[6000]; //
memset(msave,0,sizeof(msave));
int msavesave = 0;
while (ProcessMessage()==0) {
//切り替え
if (CheckHitKey(KEY_INPUT_Z)) ZKey++; else ZKey=0;
if (CheckHitKey(KEY_INPUT_X)) XKey++; else XKey=0;
if (CheckHitKey(KEY_INPUT_C)) CKey++; else CKey=0;
if (CheckHitKey(KEY_INPUT_RIGHT)) RightKey++; else RightKey=0;
if (CheckHitKey(KEY_INPUT_LEFT)) LeftKey++; else LeftKey=0;
if (CheckHitKey(KEY_INPUT_UP)) UpKey++; else UpKey=0;
if (CheckHitKey(KEY_INPUT_DOWN)) DownKey++; else DownKey=0;
if (ZKey==1) {
Index=!Index;
memset(msave,0,sizeof(msave));
msavesave = 0;
}
if (XKey==1) {
Shader++;
if (Shader==1) {
SetUseNormalDrawShader(TRUE);
MV1SetUseOrigShader(FALSE);
SetUseVertexShader(-1);
SetUsePixelShader(-1);
} else if (Shader==2) {
SetUseNormalDrawShader(FALSE);
MV1SetUseOrigShader(TRUE);
if (Index) {
SetUseVertexShader(VertexShaderHandle);
} else {
SetUseVertexShader(MV1VertexShaderHandle);
}
SetUsePixelShader(PixelShaderHandle);
} else {
MV1SetUseOrigShader(FALSE);
SetUseVertexShader(-1);
SetUsePixelShader(-1);
Shader=0;
}
memset(msave,0,sizeof(msave));
msavesave = 0;
}
if (CKey==1) {
SetPos=!SetPos;
MV1SetPosition(ModelHandle,VGet(0,0,0));
MV1RefreshReferenceMesh(ModelHandle,-1,TRUE);
memset(msave,0,sizeof(msave));
msavesave = 0;
}
if (LeftKey==1) {
XZ_Max--;
if (XZ_Max<0) XZ_Max=0;
memset(msave,0,sizeof(msave));
msavesave = 0;
}
if (RightKey==1) {
XZ_Max++;
memset(msave,0,sizeof(msave));
msavesave = 0;
}
if (DownKey==1) {
Y_Max--;
if (Y_Max<0) Y_Max=0;
memset(msave,0,sizeof(msave));
msavesave = 0;
}
if (UpKey==1) {
Y_Max++;
memset(msave,0,sizeof(msave));
msavesave = 0;
}
//リセット
memset(DrawVertex,0,sizeof(DrawVertex));
memset(DrawIndex,0,sizeof(DrawIndex));
DrawVertexNum=0;
DrawPolygonNum=0;
DrawIndexNum=0;
int DrawedVertexNum=0;
ClearDrawScreen();
//モデルを並べる
GameTime=GetNowCount();
for (int x=-XZ_Max;x<XZ_Max;x++) {
for (int z=0;z<XZ_Max;z++) {
for (int y=-Y_Max;y<Y_Max;y++) {
if (SetPos || !Index) {
MV1SetPosition(ModelHandle,VGet(320.0f+x*MODEL_SIZE,240.0f+y*MODEL_SIZE,z*MODEL_SIZE));
if (Index) {
MV1RefreshReferenceMesh(ModelHandle,-1,TRUE);
} else {
MV1DrawModel(ModelHandle);
}
}
if (Index) {
MV1_REF_POLYGONLIST PolygonList = MV1GetReferenceMesh(ModelHandle,-1,TRUE);
//限界超え
if (DrawVertexNum+PolygonList.VertexNum>DRAW_VERTEX_MAX || DrawVertexNum+PolygonList.VertexNum>WORD_MAX || DrawIndexNum+PolygonList.PolygonNum*3>DRAW_VERTEX_MAX) {
if (Shader==2) {
if (DrawVertexNum>DRAW_VERTEX_MAX || DrawVertexNum<1) {
int a=0; //●ブレークポイント
}
if (DrawIndexNum>DRAW_VERTEX_MAX || DrawIndexNum<1) {
int a=0; //●ブレークポイント
}
DrawPolygonIndexed3DToShader(DrawVertexToShader,DrawVertexNum,DrawIndex,DrawIndexNum);
} else {
DrawPolygonIndexed3D(DrawVertex,DrawVertexNum,DrawIndex,DrawPolygonNum,TextureHandle,TRUE);
}
memset(DrawVertex,0,sizeof(DrawVertex));
memset(DrawIndex,0,sizeof(DrawIndex));
DrawedVertexNum+=DrawVertexNum;
DrawVertexNum=0;
DrawPolygonNum=0;
DrawIndexNum=0;
}
//
if (Shader==2) {
if (SetPos) {
for (int i=0;i<PolygonList.VertexNum;i++) {
//
DrawVertexToShader[DrawVertexNum+i].pos = PolygonList.Vertexs[i].Position;
DrawVertexToShader[DrawVertexNum+i].norm = PolygonList.Vertexs[i].Normal;
DrawVertexToShader[DrawVertexNum+i].dif = PolygonList.Vertexs[i].DiffuseColor;
DrawVertexToShader[DrawVertexNum+i].spc = PolygonList.Vertexs[i].SpecularColor;
DrawVertexToShader[DrawVertexNum+i].u = PolygonList.Vertexs[i].TexCoord[0].u;
DrawVertexToShader[DrawVertexNum+i].v = PolygonList.Vertexs[i].TexCoord[0].v;
DrawVertexToShader[DrawVertexNum+i].su = PolygonList.Vertexs[i].TexCoord[1].u;
DrawVertexToShader[DrawVertexNum+i].sv = PolygonList.Vertexs[i].TexCoord[1].v;
//DrawVertexToShader[DrawVertexNum+i].spos = {0,0,0,0};
//DrawVertexToShader[DrawVertexNum+i].binorm = {0,0,0};
//DrawVertexToShader[DrawVertexNum+i].tan = {0,0,0};
}
} else {
for (int i=0;i<PolygonList.VertexNum;i++) {
//
DrawVertexToShader[DrawVertexNum+i].pos.x = PolygonList.Vertexs[i].Position.x+320.0f+x*MODEL_SIZE;
DrawVertexToShader[DrawVertexNum+i].pos.y = PolygonList.Vertexs[i].Position.y+240.0f+y*MODEL_SIZE;
DrawVertexToShader[DrawVertexNum+i].pos.z = PolygonList.Vertexs[i].Position.z+z*MODEL_SIZE;
DrawVertexToShader[DrawVertexNum+i].norm = PolygonList.Vertexs[i].Normal;
DrawVertexToShader[DrawVertexNum+i].dif = PolygonList.Vertexs[i].DiffuseColor;
DrawVertexToShader[DrawVertexNum+i].spc = PolygonList.Vertexs[i].SpecularColor;
DrawVertexToShader[DrawVertexNum+i].u = PolygonList.Vertexs[i].TexCoord[0].u;
DrawVertexToShader[DrawVertexNum+i].v = PolygonList.Vertexs[i].TexCoord[0].v;
DrawVertexToShader[DrawVertexNum+i].su = PolygonList.Vertexs[i].TexCoord[1].u;
DrawVertexToShader[DrawVertexNum+i].sv = PolygonList.Vertexs[i].TexCoord[1].v;
//DrawVertexToShader[DrawVertexNum+i].spos = {0,0,0,0};
//DrawVertexToShader[DrawVertexNum+i].binorm = {0,0,0};
//DrawVertexToShader[DrawVertexNum+i].tan = {0,0,0};
}
}
} else {
if (SetPos) {
for (int i=0;i<PolygonList.VertexNum;i++) {
//
DrawVertex[DrawVertexNum+i].pos = PolygonList.Vertexs[i].Position;
DrawVertex[DrawVertexNum+i].norm = PolygonList.Vertexs[i].Normal;
DrawVertex[DrawVertexNum+i].dif = PolygonList.Vertexs[i].DiffuseColor;
DrawVertex[DrawVertexNum+i].spc = PolygonList.Vertexs[i].SpecularColor;
DrawVertex[DrawVertexNum+i].u = PolygonList.Vertexs[i].TexCoord[0].u;
DrawVertex[DrawVertexNum+i].v = PolygonList.Vertexs[i].TexCoord[0].v;
DrawVertex[DrawVertexNum+i].su = PolygonList.Vertexs[i].TexCoord[1].u;
DrawVertex[DrawVertexNum+i].sv = PolygonList.Vertexs[i].TexCoord[1].v;
}
} else {
for (int i=0;i<PolygonList.VertexNum;i++) {
//
DrawVertex[DrawVertexNum+i].pos.x = PolygonList.Vertexs[i].Position.x+320.0f+x*MODEL_SIZE;
DrawVertex[DrawVertexNum+i].pos.y = PolygonList.Vertexs[i].Position.y+240.0f+y*MODEL_SIZE;
DrawVertex[DrawVertexNum+i].pos.z = PolygonList.Vertexs[i].Position.z+z*MODEL_SIZE;
DrawVertex[DrawVertexNum+i].norm = PolygonList.Vertexs[i].Normal;
DrawVertex[DrawVertexNum+i].dif = PolygonList.Vertexs[i].DiffuseColor;
DrawVertex[DrawVertexNum+i].spc = PolygonList.Vertexs[i].SpecularColor;
DrawVertex[DrawVertexNum+i].u = PolygonList.Vertexs[i].TexCoord[0].u;
DrawVertex[DrawVertexNum+i].v = PolygonList.Vertexs[i].TexCoord[0].v;
DrawVertex[DrawVertexNum+i].su = PolygonList.Vertexs[i].TexCoord[1].u;
DrawVertex[DrawVertexNum+i].sv = PolygonList.Vertexs[i].TexCoord[1].v;
}
}
}
//
for (int i=0;i<PolygonList.PolygonNum;i++) {
DrawIndex[DrawIndexNum] = (WORD)(PolygonList.Polygons[i].VIndex[0]+DrawVertexNum);
DrawIndex[DrawIndexNum+1] = (WORD)(PolygonList.Polygons[i].VIndex[1]+DrawVertexNum);
DrawIndex[DrawIndexNum+2] = (WORD)(PolygonList.Polygons[i].VIndex[2]+DrawVertexNum);
DrawIndexNum+=3;
}
DrawVertexNum+=PolygonList.VertexNum;
DrawPolygonNum+=PolygonList.PolygonNum;
//CalcPolygonBinormalAndTangentsToShader(&DrawVertexToShader[DrawVertexNum-PolygonList.VertexNum],PolygonList.PolygonNum);
}
}
}
}
//描画
if (Index) printfDx("Index:Use\n"); else printfDx("Index:NotUse\n");
if (Shader==2) {
printfDx("Shader:Original\n");
if (DrawVertexNum>DRAW_VERTEX_MAX || DrawVertexNum<1) {
int a=0; //●ブレークポイント
}
if (DrawIndexNum>DRAW_VERTEX_MAX || DrawIndexNum<1) {
int a=0; //●ブレークポイント
}
DrawPolygonIndexed3DToShader(DrawVertexToShader,DrawVertexNum,DrawIndex,DrawIndexNum);
} else {
if (Shader) printfDx("Shader:Default\n"); else printfDx("Shader:NotUse\n");
DrawPolygonIndexed3D(DrawVertex,DrawVertexNum,DrawIndex,DrawPolygonNum,TextureHandle,TRUE);
}
if (SetPos) printfDx("MV1SetPostion:Use\n"); else printfDx("MV1SetPostion:NotUse\n");
DrawedVertexNum+=DrawVertexNum;
//平均
if (!msave[6000-1]) {
msavesave=0;
for (int i=0;i<6000;i++) {
if (msave[i]) {
msavesave+=msave[i];
} else {
msave[i] = (GetNowCount()-GameTime);
msavesave+=msave[i];
msavesave = msavesave/(i+1);
i=6000;
}
}
}
printfDx("Time:%dms\nVertex:%d\n",msavesave,DrawedVertexNum);
ScreenFlip();
clsDx();
}
//終了
MV1InitModel();
InitShader();
DxLib_End();
return 0;
}