I'm probably doing something elementary wrong, but I really need some help with this as I've got a huge memory problem in my game.
I've made an example project to demonstrate the problem I'm having:
main.cpp
Code: Select all
#include <irrlicht.h>
#include "TestObject.h"
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
/*#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif*/
int main()
{
IrrlichtDevice* m_Device = createDevice(video::EDT_OPENGL, dimension2d<u32>(640, 480), 16, 0, 0, 0, 0);
IVideoDriver* m_Driver = m_Device->getVideoDriver();
ISceneManager* m_Smgr = m_Device->getSceneManager();
IGUIEnvironment* m_Guienv = m_Device->getGUIEnvironment();
TestObject* m_TestObject = new TestObject();
m_TestObject->Init(m_Device);
m_TestObject->Terminate();
m_Smgr->addCameraSceneNode(0, vector3df(0, 30, -40), vector3df(0, 5 ,0));
while(m_Device->run())
{
m_Driver->beginScene(1, 1, SColor(255, 100, 101, 140));
m_Smgr->drawAll();
m_Guienv->drawAll();
m_Driver->endScene();
}
m_Device->drop();
return 0;
}
Code: Select all
#include <irrlicht.h>
#pragma once
class TestObject
{
public:
TestObject(void);
~TestObject(void);
void Init(irr::IrrlichtDevice* p_Device);
void Terminate();
private:
irr::scene::IMeshSceneNode* m_Level;
irr::IrrlichtDevice* m_Device;
};
Code: Select all
#include "TestObject.h"
TestObject::TestObject(void)
{
}
TestObject::~TestObject(void)
{
}
void TestObject::Init(irr::IrrlichtDevice* p_Device)
{
m_Device = p_Device;
m_Level = m_Device->getSceneManager()->addMeshSceneNode(m_Device->getSceneManager()->getMesh("Media/Environment/lvl01.3ds"));
m_Level->setRotation(irr::core::vector3df(90, 0, 0));
m_Level->setMaterialFlag(irr::video::EMF_LIGHTING, 0);
}
void TestObject::Terminate()
{
m_Level->remove();
delete this;
}
This however seems to not be the case, since the memory shows a smaller decrease when using this approach, then when first for example manually dropping the mesh and then using the 'remove()' command.
I'd like to know how to properly clean everything that has to do with the scenenode from memory. I've already tried these:
Code: Select all
m_Smgr->clear();
m_Driver->removeAllTextures();
m_Driver->removeAllHardwareBuffers();
m_Guienv->clear();
Could someone assist me with solving this problem, please?
Much obliged,
Sjors van Gelderen