Getting material from SceneNode causes memory corrupt.

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
NoName4ever
Posts: 10
Joined: Fri Dec 01, 2006 5:38 am

Getting material from SceneNode causes memory corrupt.

Post by NoName4ever »

Hi!

I'm trying to change TextureMatrix of a created scene node

Code: Select all

	
	node = smgr->addCubeSceneNode(500.0f);
        video::SMaterial& m = node->getMaterial(0);
	m.getTextureMatrix(0).setTextureScale(10,10);
It ran fine but when I try to quit, the app showed a memory heap corruption. Is it the right way to do?

Thank you
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

That should be ok, I'll check if I also get a mem leak.
NoName4ever
Posts: 10
Joined: Fri Dec 01, 2006 5:38 am

Post by NoName4ever »

I think it's maybe a bug in 1.3?
Also, is it just me or the bug is reproducable for everyone?

I'm using Vista with VS.NET 05 SP1, IRRLICHT 1.3.

thanks
NoName4ever
Posts: 10
Joined: Fri Dec 01, 2006 5:38 am

Post by NoName4ever »

Can anyone help?
Just try the simple thing in your system. Maybe it's a new bug in 1.3?
thanks
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post by Luben »

How about creating the matrix first and then setting it with SMaterial::setTextureMatrix(...)?
If you don't have anything nice to say, don't say anything at all.
NoName4ever
Posts: 10
Joined: Fri Dec 01, 2006 5:38 am

Post by NoName4ever »

Same thing happens. A memory fault occurs in SMaterial dtor.
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post by Luben »

I've tested, and it works ok for me. Maybe you'r doing something else in the memory area near your materials matrix.
If you don't have anything nice to say, don't say anything at all.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I did not find any memory corruption either. Maybe show the complete main function?
NoName4ever
Posts: 10
Joined: Fri Dec 01, 2006 5:38 am

Post by NoName4ever »

Really weird! I'm still getting the same breakpoint at SMaterial dtor everytime I quit the app.

Below is the full code that can reproduce the problem

Code: Select all

#include <irrlicht.h>
#include <iostream>

using namespace irr;

#pragma comment(lib, "Irrlicht.lib")

scene::ISceneNode* node = 0;
IrrlichtDevice* device = 0;


/*
To get events like mouse and keyboard input, or GUI events like 
"the OK button has been clicked", we need an object wich is derived from the 
IEventReceiver object. There is only one method to override: OnEvent. 
This method will be called by the engine when an event happened. 
We will use this input to move the scene node with the keys W and S.
*/
class MyEventReceiver : public IEventReceiver
{
public:
	virtual bool OnEvent(SEvent event)
	{
		/*
		If the key 'W' or 'S' was left up, we get the position of the scene node,
		and modify the Y coordinate a little bit. So if you press 'W', the node
		moves up, and if you press 'S' it moves down.
		*/

		if (node != 0 && event.EventType == irr::EET_KEY_INPUT_EVENT&&
			!event.KeyInput.PressedDown)
		{
			switch(event.KeyInput.Key)
			{
			case KEY_KEY_W:
			case KEY_KEY_S:
				{
					core::vector3df v = node->getPosition();
					v.Y += event.KeyInput.Key == KEY_KEY_W ? 2.0f : -2.0f;
					node->setPosition(v);
				}
				return true;
			case KEY_KEY_Q:
				{
					device->closeDevice();
				}
			}
		}

		return false;
	}
};


/*
The event receiver for moving a scene node is ready. So lets just create
an Irrlicht Device and the scene node we want to move. We also create some
other additional scene nodes, to show that there are also some different 
possibilities to move and animate scene nodes.
*/
int main()
{
	// let user select driver type

	video::E_DRIVER_TYPE driverType = video::EDT_DIRECT3D9;

	// create device
	MyEventReceiver receiver;

	device = createDevice( driverType, core::dimension2d<s32>(800, 600),
		16, false, false, false, &receiver);

	if (device == 0)
		return 1; // could not create selected driver.


	video::IVideoDriver* driver = device->getVideoDriver();
	scene::ISceneManager* smgr = device->getSceneManager();

	node = smgr->addCubeSceneNode(500.0f);
	node->setPosition(core::vector3df(0,-250.0f,0));
	node->setMaterialFlag(video::EMF_LIGHTING,false);
	node->setMaterialTexture(0, driver->getTexture("./media/ground.jpg"));
	node->getMaterial(0).getTextureMatrix(0).setTextureScale(30,30);
	

	scene::ICameraSceneNode * cam = smgr->addCameraSceneNodeMaya();
	cam->setTarget(core::vector3df(0,0,0));
	cam->setPosition(core::vector3df(50.0f,70.0f,0));
	device->getCursorControl()->setVisible(true);

	/*
	We have done everything, so lets draw it. We also write the current
	frames per second and the name of the driver to the caption of the
	window.
	*/
	int lastFPS = -1;

	while(device->run())
	{
		driver->beginScene(true, true, video::SColor(0,113,113,133));

		smgr->drawAll(); // draw the 3d scene
		device->getGUIEnvironment()->drawAll(); // draw the gui environment (the logo)

		driver->endScene();

		int fps = driver->getFPS();

		if (lastFPS != fps)
		{
			core::stringw tmp(L"Movement Example - Irrlicht Engine [");
			tmp += driver->getName();
			tmp += L"] fps: "; 
			tmp += fps;

			device->setWindowCaption(tmp.c_str());
			lastFPS = fps;
		}
	}

	/*
	In the end, delete the Irrlicht device.
	*/
	node->drop();
	device->drop();

	return 0;
}

And I'm using VS.NET 2005 Sp1 on Vista Ultimate and Irr 1.3.
Thanks.
NoName4ever
Posts: 10
Joined: Fri Dec 01, 2006 5:38 am

Post by NoName4ever »

Anyone with VS.NET 2005 SP1 please try the code.

Anyway, I've put a bug report here:

http://irrlicht.sourceforge.net/phpBB2/ ... p?p=121069
Post Reply