我正在研究我的游戏,并且在实现中我有来自项目各个位置的这些代码块。我正在检查变量isCreated
是否为假,以便将其绘制到GUI,但是相反,cosnole会在100s内输出一个随机数(最近的尝试显示104和120)。代码中是否有导致地址问题的内容?我不知道如何声明布尔值时会发生这样的事情。是什么导致布尔输出一个随机数?
注意:InputMenuPtr
是一个智能指针InputMenuGUI
。
编辑:isCreated
输出作为0直到我得到一致性测试#3 ...
ANOTHER编辑:下面是证明setter函数是在-事实上被使用的代码。
InputMenuGUI testMenuGUI("custom"); //create object
InputMenuGUI(std::string s){setter(s);}; // calls this constructor
void setter(std::string s){ myStyle=s;
isCreated=false;isClean=false;isActive=false;}
//this is the setter function.
淘汰原有的...
struct InputMenuGUI{
InputMenu *myMenu;
ScrImage iMenu, tMenu;
Sprite sMenu[3];
Paragraph pMenu;
Coord2 pos;///Pos is Top Mid of Menu Border
bool isCreated, isClean, isActive;
std::string myStyle;
Button clickRange;
std::map<int, ScrImage> screenMap;
std::map<int, Sprite> spriteMap;
std::map<int, Paragraph> textMap;
std::map<int, Button> buttonMap;
///--------------------------------------------
InputMenuGUI(){setter("custom");};
InputMenuGUI(std::string s){setter(s);};
void setter(std::string s){ myStyle=s;
isCreated=false;isClean=false;isActive=false;}
void display(Gorilla::Silverback *gameSB, Ogre::Viewport *gameVP, Coord2 anchorT);///->
}
void GameApp::startInputMenu(){
{///Escape Menu (Testing Phase)
//Create menu, add params
InputMenu testMenu("Really Exit?");
testMenu.addButton(ChoiceButton("Please!",1,10));
testMenu.addButton(ChoiceButton("I'm kiddin!",2,12));
//create menu's gui, link ptr of menu, set menu gui ptr in map
InputMenuGUI testMenuGUI("custom");
std::cout<<"testing: " << testMenuGUI.isCreated << std::endl;
testMenuGUI.myMenu=&testMenu;
std::cout<<"testing2: " << testMenuGUI.isCreated << std::endl;
appMenu["ExitMenu"].reset(&testMenuGUI);
printf("Testing Consistency #%d: %d\n", 1, testMenuGUI.isCreated);
printf("Testing Consistency #%d: %d\n", 2, appMenu["ExitMenu"]->isCreated);
}
///start the input menus for GUI
}
void GameApp::loopInput(){
if(myKeyboard->isKeyDown(OIS::KC_ESCAPE)){
std::cout<< "Pushing menu"<<std::endl;
printf("Testing Consistency #%d: %d\n", 5, appMenu["ExitMenu"]->isCreated);
myGUI.pushMenu(appMenu["ExitMenu"]);
}
{
void GameUI::pushMenu(InputMenuPtr i){
Coord2 tAnchor((*myGameAnchor)["T"]);
tAnchor.add(0,(*myGameAnchor)["B"].y/4);
printf("Testing Consistency #%d: %d\n", 4, i->isCreated);
///Note: when changing res, update menu positions
///ToDo: Movable menus. if you hold the mouse button down, have notes on the last pos to make a relative movement
activeMenus.push_back(i);
printf("Testing Consistency #%d: %d\n", 3, i->isCreated);
i->display(myGameSB,myGameVP,tAnchor);
std::cout<<"Menu pushed"<<std::endl;
}
void InputMenuGUI::display(Gorilla::Silverback *gameSB, Ogre::Viewport *gameVP, Coord2 anchorT){
std::cout<<"testing created: "<<isCreated<<std::endl;
if(!isCreated){
//...
}
投票结束,因为缺乏示例。相关代码未显示。 –
调试器将是最有帮助的。 –
简短回答:内存损坏/未定义的行为在代码中没有显示在这里。 –