My GUI system is based on the Irrlicht GUI system and I have a memory leak that I cannot find.
Here is a simple example that shows the issue. Any help would be greatly appreciated.
Debug mode gives me this error when exiting the program, pointing to the statictext object that was created
Code: Select all
Detected memory leaks!
Dumping objects ->
{1995} normal block at 0x000001EBC27636C0, 16 bytes long.
Data: <T e s t i n g > 54 00 65 00 73 00 74 00 69 00 6E 00 67 00 00 00
{1994} normal block at 0x000001EBC79E3660, 1 bytes long.
Data: < > 00
{1993} normal block at 0x000001EBC79E3320, 2 bytes long.
Data: < > 00 00
D:\_Programming\Irrlicht Game Engine\_Externals\Irrlicht\source\Irrlicht\CGUIEnvironment.cpp(1307) : {1991} client block at 0x000001EBC277C900, subtype 0, 416 bytes long.
Data: <` + + > 60 F3 2B 14 FB 7F 00 00 98 F5 2B 14 FB 7F 00 00
Object dump complete.
The program '[19064] 000_SandBox.exe' has exited with code 0 (0x0).
Code: Select all
// 000_SandBox.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include "Irrlicht.h"
#ifdef _DEBUG
#pragma comment(lib, "Irrlicht64_debug.lib") // link to the correct library based on build type
#else
#pragma comment(lib, "Irrlicht64.lib") // link to the correct library based on build type
#endif
using namespace irr;
using namespace core;
using namespace scene;
using namespace io;
using namespace scene;
using namespace gui;
using namespace video;
IrrlichtDevice* gDevice = nullptr;
IVideoDriver* gDriver = nullptr;
ISceneManager* gSmgr = nullptr;
IGUIEnvironment* gGUI = nullptr;
#define MY_ELEMENT_TYPE 200
// derive a new class from the base guielement class
class myGuiElement : public IGUIElement
{
public:
myGuiElement(IGUIEnvironment* environment, IGUIElement* parent, s32 id, const core::rect<s32>& r)
: IGUIElement((EGUI_ELEMENT_TYPE)MY_ELEMENT_TYPE, environment, parent == nullptr ? environment->getRootGUIElement() : parent, id, r)
{
// drop this to keep the refrencecounter correct
drop();
}
};
// derive a new class from the myGuiElement class
class myGuiElement_StaticText : public myGuiElement
{
public:
myGuiElement_StaticText(IGUIEnvironment* environment, IGUIElement* parent, s32 id, const core::rect<s32>& r)
: myGuiElement(environment, parent, id, r)
{
// add a child statictext to this instance
IGUIStaticText* st = environment->addStaticText(L"Testing", r, true, false, this, id, true);
}
};
void createScene()
{
// create an instance with the gGUI rootnode as the parent
myGuiElement* e = new myGuiElement(gGUI, nullptr, 1, recti(100, 100, 300, 400));
// create an instance with the above 'e' as the parent
myGuiElement_StaticText* t = new myGuiElement_StaticText(gGUI, e, 1, recti(0, 0, 100, 30));
}
int main()
{
gDevice = createDevice(video::EDT_OPENGL, dimension2d<u32>(640, 480), 16, false, false, false, 0);
if (!gDevice) return 1;
gDriver = gDevice->getVideoDriver();
gSmgr = gDevice->getSceneManager();
gGUI = gDevice->getGUIEnvironment();
createScene();
while (gDevice->run())
{
gDriver->beginScene(true, true, SColor(255, 100, 101, 140));
gSmgr->drawAll();
gGUI->drawAll();
gDriver->endScene();
}
gDevice->drop();
return 0;
}