Horde3D
http://horde3d.org/forums/

[solved] Segmentation fault in createTexture2D
http://horde3d.org/forums/viewtopic.php?f=3&t=426
Page 1 of 1

Author:  cantele [ 17.07.2008, 14:06 ]
Post subject:  [solved] Segmentation fault in createTexture2D

Ok, so I was doing some experimenting with creating textures on the fly. I ended up creating the same texture twice. Now, the documentation tells that if the resource already exists, the function fails. However it didn't mention it fails with a segmentation fault, randomly:

#0 0xb7be5032 in RendererBase::destroyRenderBuffer () libHorde3D.so
#1 0xb7c097e4 in Texture2DResource::release () from libHorde3D.so
#2 0xb7c09877 in Texture2DResource::~Texture2DResource () from libHorde3D.so
#3 0xb7bc2871 in createTexture2D () from libHorde3D.so

To reproduce, just call it like e.g. this:

std::cout << "WORK XX " << res << std::endl;
res = Horde3D::createTexture2D("norfdsfdsmal2",
ResourceFlags::NoTexRepeat|
ResourceFlags::NoTexCompression|
ResourceFlags::NoTexMipmaps|
ResourceFlags::NoTexFiltering,
width, height, false);
std::cout << "WORK XY " << res << std::endl;
res = Horde3D::createTexture2D("norfdsfdsmal2",
ResourceFlags::NoTexRepeat|
ResourceFlags::NoTexCompression|
ResourceFlags::NoTexMipmaps|
ResourceFlags::NoTexFiltering,
width, height, false);
std::cout << "WORK XZ " << res << std::endl;
res = Horde3D::createTexture2D("norfdsfdsmal2",
ResourceFlags::NoTexRepeat|
ResourceFlags::NoTexCompression|
ResourceFlags::NoTexMipmaps|
ResourceFlags::NoTexFiltering,
width, height, false);
std::cout << "WORK XW " << res << std::endl;

That could produce for example:

WORK XX 0
WORK XY 47
./simple_run.sh: line 1: 31572 Segmentation fault

or

WORK XX 0
WORK XY 47
WORK XZ 0

depending on luck.

Author:  cantele [ 17.07.2008, 14:27 ]
Post subject:  Re: Segmentation fault in createTexture2D

If I try to do

"removeResource" followed by "releaseUnusedResources" to make sure the same resource shouldn't be there anymore, I get the same segmentation fault. It just seems destroyRenderBuffer is somehow broken. And I didn't even set the "renderable" flag to true when creating the texture.

This time with:

#0 0xb7c7a032 in RendererBase::destroyRenderBuffer () from libHorde3D.so
#1 0xb7c9e7e4 in Texture2DResource::release () from libHorde3D.so
#2 0xb7c8b0ab in ResourceManager::releaseUnusedResources () from libHorde3D.so
#3 0xb7c5789b in releaseUnusedResources () from libHorde3D.so

Author:  cantele [ 17.07.2008, 14:32 ]
Post subject:  Re: Segmentation fault in createTexture2D

BTW, if you want to fix this, you should set

_rendBuf=0x0;

in Texture2DResource constructor, if the renderable flag is false. Just a thought: Why are C++ initializer lists never used in the engine? This is not java, you don't have default values for pointers or any other values for the matter.

Author:  Volker [ 18.07.2008, 16:39 ]
Post subject:  Re: Segmentation fault in createTexture2D

Is the
Code:
_rendBuf=0x0;

statement the fix for all of the problems above?

Author:  cantele [ 18.07.2008, 19:03 ]
Post subject:  Re: Segmentation fault in createTexture2D

Yeah, it fixes the problems. Sorry for elaborating too much. It's a simple thing - if the texture isn't renderable, then it's destructor tries to free a buffer that has never been allocated. It tests whether it's 0, but it's never been initialized... the same when unloading resources by hand...

Author:  Volker [ 18.07.2008, 19:40 ]
Post subject:  Re: Segmentation fault in createTexture2D

Fixed it in the SVN,... thanks for pointing it out

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/