directdraw程序假死机的问题

zeronecpp 2006-02-13 09:01:20
我初学directx, 写了个简单的游戏程序, 运行的时候,同样的程序有时候没问题, 但有时候编译之后就会进入就不动了. 而且在我的机器上可以很好的运行时,在别的(已装directx runtime)机器上会假死机. 有人能解决这个问题吗? 是我的程序的问题还是别的什么问题呢?
...全文
134 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Bobby136 2006-02-14
  • 打赏
  • 举报
回复
楼上的代码没有用到directx

你的机子的显示设置,显卡等和别人的机子不同,也有可能出问题
zeronecpp 2006-02-13
  • 打赏
  • 举报
回复
这是主要的类的代码,继承自一个实现初始化环境等工作的基类


CBricksGame::CBricksGame(void)
{

}

CBricksGame::~CBricksGame(void)
{
}

bool CBricksGame::FreshGrid()
{
int i;
int j;
for(i=0;i<12;i++)
{
for(j=0;j<16;j++)
{
int tmp=MapGrid[i][j];
Grid[i][j]=tmp;
}
}
return true;
}
bool CBricksGame::CreateBrick()
{
srand(GetTickCount());
shp=rand()%7;
style=rand()%4;
m_x=5;
m_y=0;
return true;
}
bool CBricksGame::ProcKey()
{
if(!GetKeyboardState(m_key_state)) return false;
if(m_key_state[DIK_ESCAPE] & 0x80)
PostQuitMessage(0);
else if(m_key_state[DIK_RIGHT] & 0x80)
{
if(!FreshGrid())return false;
if(m_x+shape[shp][style][17]<12) m_x++;
}
else if(m_key_state[DIK_LEFT]& 0x80)
{
if(!FreshGrid())return false;
if(m_x>0) m_x--;
}
else if(m_key_state[DIK_DOWN] & 0x80)
{
if(!FreshGrid())return false;
if(!ProcDown())return false;
}
else if(m_key_state[DIK_SPACE] & 0x80)
{

style=((style+1)%4);
if(!FreshGrid())return false;
}
//暂时的测试函数
else if(m_key_state[DIK_A] & 0x80)
{
if(!FreshGrid())return false;
CreateBrick();
}
return true;
}
bool CBricksGame::CleanGrid()
{
int i;
int j;
for(i=0;i<12;i++)
{
for(j=0;j<16;j++)
{

Grid[i][j]=0;
}
}
return true;
}

bool CBricksGame::DoLine()
{
if(!FreshGrid())return false;
int mark=1;
int i,j;
for(i=0;i<16;i++)
{
for(j=0;j<12;j++)
{
if(Grid[j][i]==0)
{
mark=0;
break;
}
}
if(mark==1)
{
int a,b;
for(a=i;a>0;a--)
{
for(b=0;b<12;b++)
{
Grid[b][a]=Grid[b][a-1];
}
}

}
mark=1;
}
for(i=0;i<12;i++)
{
for(j=0;j<16;j++)
{
MapGrid[i][j]=Grid[i][j];
}
}
return true;
}

bool CBricksGame::ProcDown()
{
int i,j;
int mark=0;

if(!CleanGrid())return false;
for(i=0;i<4;i++)
Grid[m_x][i+m_y+1]+=shape[shp][style][i];
for(i=4;i<8;i++)
Grid[m_x+1][i+m_y+1-4]+=shape[shp][style][i];
for(i=8;i<12;i++)
Grid[m_x+2][i+m_y+1-8]+=shape[shp][style][i];
for(i=12;i<16;i++)
Grid[m_x+3][i+m_y+1-12]+=shape[shp][style][i];

for(i=0;i<12;i++)
{
for(j=0;j<16;j++)
{
if((Grid[i][j]+MapGrid[i][j])==2||m_y+shape[shp][style][16]==16)
{
mark=1;//发生碰撞
break;
}
}
if(mark==1) break;
}
if(mark==1)
{
if(!FreshGrid())return false;
for(i=0;i<4;i++)
Grid[m_x][i+m_y]+=shape[shp][style][i];
for(i=4;i<8;i++)
Grid[m_x+1][i+m_y-4]+=shape[shp][style][i];
for(i=8;i<12;i++)
Grid[m_x+2][i+m_y-8]+=shape[shp][style][i];
for(i=12;i<16;i++)
Grid[m_x+3][i+m_y-12]+=shape[shp][style][i];
for(i=0;i<12;i++)
{
for(j=0;j<16;j++)
{
MapGrid[i][j]=Grid[i][j];
}
}
if(!DoLine())return false;
if(!CreateBrick())return false;
}
else if(mark==0&&m_y+shape[shp][style][16]<16)
{
m_y++;
if(!FreshGrid()) return false;
}
return true;
}
bool CBricksGame::DrawGrid()
{
int i;
int j;
RECT rect;

for(i=0;i<16;i++)
{
for(j=0;j<12;j++)
{

if(Grid[j][i]==1)
{
rect.right=(j+1)*m_blockwidth+m_stagex;
rect.left=j*m_blockwidth+m_stagex;
rect.top=i*m_blockwidth+m_stagey;
rect.bottom=(i+1)*m_blockwidth+m_stagey;
if(!DrawRectangle(&rect,m_blockclr))return false;
if(!DrawFrame(rect)) return false;
}

}

}
return true;
}

bool CBricksGame::DrawFrame(const RECT rect)
{
RECT frect;
bool br = false;
frect.left = rect.left;
frect.top = rect.top;
frect.right = rect.left + 1;
frect.bottom = rect.bottom;

if(!DrawRectangle(&frect,m_framelight))return false;

frect.left = rect.left;
frect.top = rect.top;
frect.right = rect.right;
frect.bottom = rect.top + 1;

if(!DrawRectangle(&frect,m_framelight))return false;

frect.left = rect.right - 1;
frect.top = rect.top;
frect.right = rect.right;
frect.bottom = rect.bottom;

if(!DrawRectangle(&frect,m_framedark))return false;

frect.left = rect.left + 1;
frect.top = rect.bottom - 1;
frect.right = rect.right;
frect.bottom = rect.bottom;

if(!DrawRectangle(&frect,m_framedark))return false;

return true;
}

bool CBricksGame::DrawBorder()
{
RECT leftborder;
RECT rightborder;
leftborder.left=m_stagex-20;
leftborder.right=m_stagex;
leftborder.top=m_stagey-20;
leftborder.bottom=600;
rightborder.left=m_stagex+240;
rightborder.right=m_stagex+260;
rightborder.top=m_stagey-20;
rightborder.bottom=600;
if(!DrawRectangle(&rightborder,m_framedark))return false;
if(!DrawRectangle(&leftborder,m_framedark))return false;
if(!DrawFrame(rightborder))return false;
if(!DrawFrame(leftborder))return false;
return true;
}
bool CBricksGame::DoBlocks(int height,int colum)
{
int i;
for(i=0;i<4;i++)
if(Grid[height][i+colum]==0) Grid[height][i+colum]+=shape[shp][style][i];
for(i=4;i<8;i++)
if(Grid[height+1][i+colum-4]==0) Grid[height+1][i+colum-4]+=shape[shp][style][i];
for(i=8;i<12;i++)
if(Grid[height+2][i+colum-8]==0)Grid[height+2][i+colum-8]+=shape[shp][style][i];
for(i=12;i<16;i++)
if(Grid[height+3][i+colum-12]==0)Grid[height+3][i+colum-12]+=shape[shp][style][i];


return true;
}

bool CBricksGame::GameInit()
{
int i,j;
for(i=0;i<12;i++)
{
for(j=0;j<16;j++)
{
Grid[i][j]=0;
MapGrid[i][j]=0;
}
Grid[i][16]=1;
MapGrid[i][16]=1;
}

m_x=2;
m_y=0;
m_blockwidth=20;
shp=0;
style=0;
m_framelight= RGBto16BitColor(255,255,255);
m_framedark= RGBto16BitColor(132,130,132);
m_background = RGBto16BitColor(0,0,0);
m_blockclr = RGBto16BitColor(0,10,250);
m_stagex=280;
m_stagey=260;
title="俄罗斯方块v0.01简陋版";

//字体
m_title_font = CreateFont
(
45,
0,
0,
0,
FW_HEAVY,
FALSE,
FALSE,
FALSE,
DEFAULT_CHARSET,
OUT_CHARACTER_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH | FF_DONTCARE,
"楷体"
);
m_main_font = CreateFont
(
24,
0,
0,
0,
FW_HEAVY,
FALSE,
FALSE,
FALSE,
DEFAULT_CHARSET,
OUT_CHARACTER_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH | FF_DONTCARE,
"MS Sans Serif"
);
return true;
}
bool CBricksGame::ProcTimer()
{
timer=(timer+1)%10;
if(timer==9)
if(!ProcDown())return false;
return true;
}
bool CBricksGame::DrawText()
{
StartGDIDrawing();
if(!DrawGDIText((LPTSTR)title.c_str(),0xff,0xff,0xff,m_title_font,10,10))return false;
if(!DrawGDIText("作者:Zéruncpp 方向键调整位置 空格键变相 ESC退出",0x99,0x99,0x99,m_main_font,70,70))return false;
EndGDIDrawing();
return true;
}
bool CBricksGame::GameProc()
{
if(!ProcKey())return false;
if(!FreshGrid()) return false;
if(!ProcTimer())return false;
if(!DoBlocks(m_x,m_y))return false;

if(!StartScene(m_background))return false;

if(!DrawText())return false;
if(!DrawBorder())return false;
if(!DrawGrid())return false;


if(!EndScene())return false;
return true;
}
寻开心 2006-02-13
  • 打赏
  • 举报
回复
另外一个单机全屏幕调试的技巧
http://www.source520.com/infoview/Article_22787.html
寻开心 2006-02-13
  • 打赏
  • 举报
回复
应该是你用的某些功能,客户的计算机不支持
建议你用远程debug来调试跟踪问题的所在
远程debug的方法在这里:
http://topic.csdn.net/t/20031205/15/2531779.html
answerear 2006-02-13
  • 打赏
  • 举报
回复
把源码贴出来看看
寻开心 2006-02-13
  • 打赏
  • 举报
回复
这样很难看出问题所在
自己debug出问题的所在,然后才提问解决问题吧

在窗口模式下,或者远程调试的情况下,把ddraw假死机的时候程序的定位点找到,然后才好分析

8,303

社区成员

发帖
与我相关
我的任务
社区描述
游戏开发相关内容讨论专区
社区管理员
  • 游戏开发
  • 呆呆敲代码的小Y
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧