I've encountered a weird problem manually adding meshes to the mesh cache.
I simplified my code to the following and still crashes when trying to get the mesh name of mesh2
Code: Select all
scene::IMesh* mesh1 = smgr->getMesh("media/tank_armor.b3d");
scene::SMesh* newMesh = new scene::SMesh();
smgr->getMeshCache()->addMesh("randomName", (scene::IAnimatedMesh*) newMesh); // If i remove this line, everything works perferctly
scene::IMesh* mesh2 = smgr->getMesh("media/tank_turret.b3d");
smgr->getMeshCache()->getMeshName(mesh1);
smgr->getMeshCache()->getMeshName(mesh2); // Crash here
Testcase:
Code: Select all
#include <irrlicht.h>
#include "driverChoice.h"
using namespace irr;
int main() {
// ask user for driver
//video::E_DRIVER_TYPE driverType = driverChoiceConsole();
video::E_DRIVER_TYPE driverType = video::EDT_OPENGL;
if (driverType == video::EDT_COUNT)
return 1;
// create device with full flexibility over creation parameters
// you can add more parameters if desired, check irr::SIrrlichtCreationParameters
irr::SIrrlichtCreationParameters params;
params.DriverType = driverType;
params.WindowSize = core::dimension2d<u32>(1024, 768);
params.Bits = 32;
IrrlichtDevice* device = createDeviceEx(params);
if (device == 0)
return 1; // could not create selected driver.
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
gui::IGUIEnvironment* env = device->getGUIEnvironment();
// Some meshes
scene::IMesh* mesh1 = smgr->getMesh("media/tank_armor.b3d");
scene::SMesh* newMesh = new scene::SMesh();
smgr->getMeshCache()->addMesh("randomName", (scene::IAnimatedMesh*) newMesh);
scene::IMesh* mesh2 = smgr->getMesh("media/tank_turret.b3d");
smgr->getMeshCache()->getMeshName(mesh1);
smgr->getMeshCache()->getMeshName(mesh2); // Crash here
while (device->run()) {
if (device->isWindowActive()) {
driver->beginScene(true, true, 0);
smgr->drawAll();
env->drawAll();
driver->endScene();
}
}
device->drop();
return 0;
}