Drop and reload a texture by image crashes

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Barratator
Posts: 30
Joined: Fri Jan 08, 2010 3:30 pm

Drop and reload a texture by image crashes

Post by Barratator »

Hello,
sorry for my bad english.

I have a problem with the memory-management with irrlicht. I want to load parts of my map dynamic. This works already well, but when I'm go away from the specific map-part the part should be free from memory.

The program loads the textures and meshs in another thread to the RAM, after that, the main-thread creates a virtual IReadFile via createMemoryReadFile and creates an image of the raw-data:

Code: Select all

[...]
IReadFile* file = currentEngine->filesystem->createMemoryReadFile(	this->jobTexture[i]->buffer,
																	this->jobTexture[i]->bufferSize,
																	(LPCTSTR)name,
																	false);
if(file)
{
	IImage* img = currentEngine->driver->createImageFromFile(file);
	if(!img)
	{
		[...]
	}
	
	[...]

	img->drop();
	file->drop();
}
[...]
free(this->jobTexture[i]->buffer);
A few frames later, the image will load to VRAM:

Code: Select all

[...]
if(!this->splattingTexture)
{
	[...]
	this->splattingTexture = currentEngine->driver->addTexture((LPCTSTR)name, this->splattingImage);
}
[...]
The first time, that works very good and performant. Later, I delete the ressources by this:

Code: Select all

[...]
if(this->meshNode)
{
	this->meshNode->remove();
	this->meshNode = NULL;
}
if(this->mesh)
{
	currentEngine->smgr->getMeshCache()->removeMesh(this->mesh);
	this->mesh = NULL;
}
if(this->splattingTexture)
{
	currentEngine->driver->removeTexture(this->splattingTexture);
	//this->splattingTexture->drop();  // i tried this before, same effect
	this->splattingTexture = NULL;
}
[...]
if(this->splattingImage)
{
	this->splattingImage->drop();
	this->splattingImage = NULL;
}
[...]
At the next loading-sequence, the program stops at the "addTexture"-Method with the following exception:
0xC0000005: Zugriffsverletzung beim Lesen an Position 0x43700000.
("Access violation reading location 0x43700000")

What can I do?

Thank you!

Greetings,
Bastian
Scarabol
Posts: 167
Joined: Sat Jan 03, 2009 5:26 pm
Location: Aachen, Germany

Post by Scarabol »

Hi,

did you check if name or this->splattingImage has the 0x43700000 value?

MfG
Scarabol
Irrlicht 1.7.2
Eclipse
Boost
Post Reply