Original Post
Hi, This class is giving me some headache...after I create an instance of it, and then tried to quit the application, I always get the exception "Stack is corrputed" at the ending brace of the main() function. I'm using VS C++ .NET 2005. The class in question is CSampleMenu, which is derived from GUIGroup. I believe that it has something to do with the destructor...I set it as virtual which is what many OOP books suggested...is there anything else I have done wrong? GUIGroup.h GUIGroup.cpp CSampleMenu.h CSampleMenu.cpp Thanks in advance!
#pragma once
#include "CEGUI_Includes.h"
class GUIGroup
{
private:
virtual void setupEventHandlers() = 0; // bind events to controls
protected:
CEGUI::Window * GroupWindow_; // parent window of the UI group
public:
virtual ~GUIGroup(void); // release all resources
virtual void onLoad(void) = 0; // initalise the GUI and its controls
virtual void onHide(void) = 0; // called when GUI group is switched for another
virtual void onShow(void) = 0; // called when the GUI group is showed
void addTo( CEGUI::Window*& dest); // add window holding all the UI to given window
void load(void); // load the gui group
void show(void); // display the window
void hide(void); // hide the window
// return the window of the group
CEGUI::Window* GetWindow(void)
{
return GroupWindow_;
}
};
#include "GUIGroup.h"
// Release all acquired resources
GUIGroup::~GUIGroup(void)
{
if (GroupWindow_)
{
delete GroupWindow_;
GroupWindow_ = 0;
}
}
void GUIGroup::addTo(CEGUI::Window*& dest)
{
dest->addChildWindow(this->GroupWindow_);
}
// Load the GUI group
void GUIGroup::load()
{
this->onLoad();
}
// Show the GUI group
void GUIGroup::show()
{
onShow();
this->GroupWindow_->show();
}
// Hide the GUI group
void GUIGroup::hide()
{
this->GroupWindow_->hide();
onHide();
}
#ifndef SAMPLE_MENU
#define SAMPLE_MENU
#include "GUIGroup.h"
/*
A sample GUIGroup to play with
*/
class CSampleMenu : public GUIGroup
{
public:
~CSampleMenu(void);
void onLoad(void); // initalise the GUI and its controls
void onHide(void) {}; // called when GUI group is switched for another
void onShow(void) {}; // called when the GUI group is showed
private:
void setupEventHandlers() {};
};
#endif
#include "SampleMenu.h"
void CSampleMenu::onLoad()
{
// Load in the imagesets
CEGUI::ImagesetManager::getSingletonPtr()->createImageset ("MenuButtons.imageset", "General");
CEGUI::ImagesetManager::getSingletonPtr()->createImageset ("MenuBackground.imageset", "General");
// Load in the layout
GUIUtil::loadLayout("Menu.layout", &GroupWindow_ );
}