Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Crash exit app with CPGUI  (Read 1855 times)

0 Members and 1 Guest are viewing this topic.

nacsasoft

  • Newbie
  • *
  • Posts: 3
    • View Profile
Crash exit app with CPGUI
« on: September 24, 2009, 08:04:02 pm »
Hi !
My name is Csaba from Hungary.

Sorry for My bad English !!!

I have a problem.I used in my app the CPGUI, and I exit the app then I get an error (memory leak). Without the CPGUI, my app is good !

This is a code (class partial) :

 

Code: [Select]


private:
cp::cpGuiContainer      myGUI;
cp::cpSelectionBox      *selBox;


public:

(..in constructor...)
selBox = new cp::cpSelectionBox(myWindow, &myGUI, 450, 70, 200, 150);

        std::string choices[] = {"Dwarf", "Elf", "Warrior", "Wizard",
"Adventurer", "Guild Leader", "Cleric"};
        for(int t=0; t < 7; t++)
            selBox->AddChoice(choices[t]);
        selBox->SetFont("BibliaMapsDatas/fonts/Ameth___.ttf",10);
        selBox->SetFontSize(16);



(... in update function...)
myWindow->GetEvent(menuEvent);
        const sf::Input& input = myWindow->GetInput();

        if ((menuEvent.Type == Event::KeyPressed) && (menuEvent.Key.Code == Key::Escape))
        {
            iGameState = 0;
        }

        myGUI.ProcessKeys(&menuEvent);
        int selection; // an int to store the selection choice from
  // our selection box & drop down box
if(selBox->CheckState(&input) == cp::CP_ST_MOUSE_LBUTTON_RELEASED)
selection = selBox->GetSelection();


       selBox->Draw();


What is the problem ?

forrestcupp

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Crash exit app with CPGUI
« Reply #1 on: September 26, 2009, 06:48:08 pm »
You probably either need to not make selBox a pointer, or delete it in your destructor.  Any time you create a pointer in a constructor, you need to delete it in your destructor, or you will have memory leaks.  That goes for any pointer, not just cpGUI ones.

 

anything