|
部分代码:
void Thread_creat(Terrain_Tile* tt)
{
buffernode& nc=const_cast<buffernode&>(tt->nowcreat);
nc.tnode=new Node_513(tt->filename,nc.wz.x*512,nc.wz.y*512,512,tt->_device);
tt->iscreatrun=false;//更改iscreatrun告诉主线程Node_513创建结束
return;
}
//这是Block_Terrain的构造函数,Block_Terrain保存着顶点缓冲等。。。
Block_Terrain(char *filename, UINT lox, UINT loz,rg1: OINT3D tl,IDirect3DDevice9* device)
{
FILE *fp;
UINT i=0;
position_x=lox/32;
position_y=(512-(loz-32))/32-1;
position_y=15-position_y;
device->CreateVertexBuffer(
33*33 * sizeof(rg1::TerrainVertex),
D3DUSAGE_WRITEONLY,
rg1::TerrainVertex::FVF,
D3DPOOL_MANAGED,
&vb,
0);
vb->Lock(0, 0, (void**)&(v), 0);
//读取高度图文件的一部分,存入V
vb->Unlock();
/*。。。。。*/
}
//这是struct Node_513的构造函数,Node_513是一个四叉树,有着4个子节点或者是一个Block_Terrain
Node_513(char *filename,UINT lox,UINT loz,UINT level,IDirect3DDevice9* device)
{
UINT c=CELL_SPACE;
br.x=lox*c+level*c;
br.y=0;
br.z=loz*c;
tl.x=lox*c;
tl.y=0;
tl.z=loz*c+level*c;
if(level>32)
{
BT=NULL;
UINT nextlevel=level/2;
child[0]=new Node_513(filename,lox,loz+nextlevel,nextlevel,device);
child[1]=new Node_513(filename,lox+nextlevel,loz+nextlevel,nextlevel,device);
child[2]=new Node_513(filename,lox,loz,nextlevel,device);
child[3]=new Node_513(filename,lox+nextlevel,loz,nextlevel,device);
}
else
{
child[0]=NULL;
child[1]=NULL;
child[2]=NULL;
child[3]=NULL;
BT=NULL;
UINT zx=lox%512;
UINT zz=loz%512;
zz=zz+32;
BT=new Block_Terrain(filename,zx,zz,tl,device);
}
}
在主线程中,正确创建Node_513的话没有任何问题,而在辅助线程中动态生成就会出错
刚刚想了一下,我的主线程的d3d 设备一直在进行渲染操作,是不是因为我在渲染的时候另一条线程在载入顶点缓冲就会出错,我该怎么办
|
|