调试断言失败-我的VC ++项目 [英] Debug assertion failed - my VC++ project

查看:105
本文介绍了调试断言失败-我的VC ++项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我一直在用Visual C ++ 6.0开发游戏项目,但是现在我遇到了一个非常糟糕的问题.当我开始游戏时,它会占用大量CPU使用率-例如60-70%.当我启动调试器时,它给了我几个错误,但是我不知道如何解决它.在整个过程中,我一直在使用位图,但我不知道这是否是原因.看一下它的外观-http://img2.imageshack.us/img2/716/guitarmaster.jpg
如您所见,开始游戏"已标记,位图具有橙色背景,其他位图具有黑色背景.标记选项后,会将另一个位图放置到原始位置.我以这种方式加载的位图

无效Game :: StartGame(CBitmap * p,CDC * pDC)
{
CDC dcMemory;
BITMAP bm;
dcMemory.CreateCompatibleDC(pDC);
dcMemory.SelectObject(p);
p-& gt; GetBitmap(& amp; bm);
int x,y;
x =(screenX * bm.bmWidth)/1280; tretchBlt(正右/2-bm.bmWidth/2,2 * y,x,y,& dcMemory,0,0,bm.bmWidth,bm.bmHeight, SRCCOPY);
}

在我的OnInitDialog()函数中,我的代码是:
CRect rect;
GetClientRect(& rect);
CClientDC clientDC(this);
pDC =新的CDC();
位图=新的CBitmap();
位图-> CreateCompatibleBitmap(& clientDC,rect.right,rect.bottom);
pDC-> CreateCompatibleDC(& clientDC);
pDC-> SelectObject(Bitmap);


在WM_TIMER(OnTimer)中,我使用以下命令:
pDC-> illSolidRect(rect,RGB(0,0,0));

然后我从上面加载位图

CBitmap startGame;
startGame.LoadBitmap(the_resource_here); //如果未标记
CBitmap startGame1;
startGame1.LoadBitmap(the_resource_here); //如果已标记-此处的位图文件不同
我有一个布尔变量来检查菜单项是否被标记-我在PreTranslateMessage();
在OnTimer()中,我继续:
if(ifStartGame == true)
StartGame(& startGame,pDC);
其他
StartGame(& startGame1,pDC);


现在是坏东西;
我的菜单项(开始游戏...关于...退出)我使用键盘上的箭头键控制它们(在PreTranslateMessage中).
当我在其中一个中按Enter键时,它叫我一个班级(例如开始游戏-一个班级,大约-其他班级)
直到我按Enter 5-6次,然后停止调用类窗口,它才能正常运行.

我将在下面发布我的PreTranslateMessage()代码:
如果(pMsg-> message == WM_KEYUP)
{
if(pMsg-> wParam == VK_DOWN)
{
if(ifStartChecked == true)//如果start为true-它使下一个为true,然后为start-false
{
ifHowToPlayChecked = true;
ifStartChecked = false;
}
否则if(ifHowToPlayChecked == true)
{
ifHowToPlayChecked = false;
ifAboutChecked = true;
}
else if(ifAboutChecked == true)//在此更改状态-我表示玩家选择一个选项
{
ifAboutChecked = false;
ifExitChecked = true;
}
否则if(ifExitChecked == true)
{
ifExitChecked = false;
ifStartChecked = true;
}
}

if(pMsg-> wParam == VK_RETURN)//如果播放器在按下菜单项输入时按下了输入
{
if(ifStartChecked == true)
{
Class1 dlg1;
dlg1.DoModal();
}
否则if(ifHowToPlayChecked == true)
{
Class2 dlg2;
dlg2.DoModal();
}
否则if(ifAboutChecked == true)
{
Class3 dlg3;
dlg3.DoModal();
}
否则if(ifExitChecked == true)
{
出口(0);
}

Hello, i have been developing a game-project in Visual C++ 6.0 but now i have an extremely bad problem. When i start my game, it gets a lot of CPU usage - like 60-70%. When i start debugger it gives me a several errors, but i have no idea how to fix it. Throughly i''m using bitmaps and i don''t know if that''s the cause. Look how it looks - http://img2.imageshack.us/img2/716/guitarmaster.jpg
As you can see "Start Game" is marked and the bitmap has orange background and the others have black background. When an option is marked it puts another bitmap to the place of original. The bitmaps i load in this way

void Game::StartGame(CBitmap *p, CDC *pDC)
{
CDC dcMemory;
BITMAP bm;
dcMemory.CreateCompatibleDC(pDC);
dcMemory.SelectObject(p);
p->GetBitmap(&bm);
int x,y;
x = (screenX*bm.bmWidth)/1280;tretchBlt(rect.right/2-bm.bmWidth/2, 2*y, x,y, &dcMemory, 0,0, bm.bmWidth, bm.bmHeight, SRCCOPY);
}

In my OnInitDialog() function my code is:
CRect rect;
GetClientRect(&rect);
CClientDC clientDC(this);
pDC = new CDC();
Bitmap = new CBitmap();
Bitmap->CreateCompatibleBitmap(&clientDC,rect.right,rect.bottom);
pDC->CreateCompatibleDC(&clientDC);
pDC->SelectObject(Bitmap);


And in WM_TIMER (OnTimer) i use the following:
pDC->illSolidRect(rect, RGB(0,0,0));

and then the bitmap from above i load there

CBitmap startGame;
startGame.LoadBitmap(the_resource_here); // if not marked
CBitmap startGame1;
startGame1.LoadBitmap(the_resource_here); // if marked - here the bitmap file is different
I have a boolean variable to check if the menu item is marked or not - I make that in PreTranslateMessage();
In OnTimer() i go on with:
if(ifStartGame == true)
StartGame(&startGame, pDC);
else
StartGame(&startGame1, pDC);


Now the bad stuff;
My menu items(Start Game... About ... Exit) i control them using Arrow Keys from keyboard(in PreTranslateMessage).
When i press Enter in one of them it calls me a class(for example for start game - one class, for about - other class)
It works perfect until i press Enter on them 5-6 times, and then it stops calling the class windows.

I''ll post my PreTranslateMessage() code below:
if (pMsg->message == WM_KEYUP)
{
if(pMsg->wParam == VK_DOWN)
{
if(ifStartChecked == true) // if start is true - it makes the next true and start - false
{
ifHowToPlayChecked = true;
ifStartChecked = false;
}
else if(ifHowToPlayChecked == true)
{
ifHowToPlayChecked = false;
ifAboutChecked = true;
}
else if(ifAboutChecked == true) // HERE I CHANGE THE STATES - I MEAN THE PLAYER CHOOSES AN OPTION
{
ifAboutChecked = false;
ifExitChecked = true;
}
else if(ifExitChecked == true)
{
ifExitChecked = false;
ifStartChecked = true;
}
}

if(pMsg->wParam == VK_RETURN) // IF THE PLAYER PRESSES ENTER IT CHECKS ON WHICH MENU ITEM ENTER IS PRESSED
{
if(ifStartChecked == true)
{
Class1 dlg1;
dlg1.DoModal();
}
else if(ifHowToPlayChecked == true)
{
Class2 dlg2;
dlg2.DoModal();
}
else if(ifAboutChecked== true)
{
Class3 dlg3;
dlg3.DoModal();
}
else if(ifExitChecked == true)
{
exit(0);
}

推荐答案

似乎您有几个问题.尝试一次带他们一个.另外,请将您的代码括在< pre></pre>标记并正确缩进.通常,提供您得到的特定错误/消息也很有用. (那些通常也是您自己开始查找问题的好地方.)

在我看来,您的设计中至少存在一个基本问题.您似乎正在尝试在整个位置上绘制窗口-以响应许多不同的事件.通常,仅在对话框的OnDraw中或在窗口的OnPaint中在窗口上绘制.为了响应其他事件,您可以更改指示程序状态的变量,以便OnDraw/OnPaint知道应显示的内容,然后调用Invalidate或InvalidateRect,以便调用OnDraw/OnPaint并告知要重画窗口的哪一部分.

我不知道您在程序中为此使用了什么计时器.从我的屏幕截图中可以看出,没有理由使用它.如果没有充分的理由使用计时器,请不要.

由于您正在为此窗口使用对话框,因此我认为您将使用按钮作为选项.这样可以简化屏幕绘制,将模式对话框的开始移到相应按钮的OnClicked位置,并且应该完全摆脱PreTranslateMessage().

我会推荐一本书,例如Jeff Prosise的使用MFC编程Windows".我还建议使用Visual C ++的更高版本,因为版本6不能与标准C ++一起使用.

祝你好运.
It seems that you have several problems. Try taking them one at a time. Also please enclose your code in <pre></pre> tags and properly indent it. In general, it is also useful to provide the specific errors/messages that you get. (Those are usually also a good place to start looking for your problems yourself.)

It appears to me that there is at least one basic problem in your design. You seem to be trying to draw on the window all over the place - in response to many different events. Normally, you draw on the window only in OnDraw for a dialog or in OnPaint for a window. In response to other events you change variables that indicate the state of the program so OnDraw/OnPaint know what should be displayed and you call Invalidate or InvalidateRect so that OnDraw/OnPaint will be called and told what part of the window to redraw.

I have no idea what you are using a timer for at this point in your program. From what I can see from your screen shot, there is no reason to use one. If there is no good reason to use a timer, don''t.

Since you are using a dialog for this window, I would think that you would be using buttons for your options. This simplifies your screen painting, moves the starting of modal dialogs to the OnClicked of the appropriate button and should entirely get rid of your PreTranslateMessage().

I would suggest a book such as "Programming Windows with MFC" by Jeff Prosise. I would also suggest a later version of Visual C++, as version 6 does not work with standard C++.

Good luck.


这篇关于调试断言失败-我的VC ++项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆