我正在研究我的遊戲,並且在實現中我有來自項目各個位置的這些代碼塊。我正在檢查變量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){
//...
}
投票結束,因爲缺乏示例。相關代碼未顯示。 –
調試器將是最有幫助的。 –
簡短回答:內存損壞/未定義的行爲在代碼中沒有顯示在這裏。 –