Horde3D
http://www.horde3d.org/forums/

safeStr in utils
http://www.horde3d.org/forums/viewtopic.php?f=3&t=1540
Page 1 of 1

Author:  johannes [ 12.06.2011, 14:28 ]
Post subject:  safeStr in utils

I use h3dutCreateGeometryRes(const char *name, ...) from the utils to generate some procedural geometry.

The function in its current form requires a unique string ("name"). Calling the function twice with the same string but different data causes strange memory overlaps that lead to broken geometry or in worst case crashes. Other functions such as h3dAddModelNode() or h3dAddMeshNode() are designed similarly. This is not a major bug, but when you use these functions to create dynamic geometry, you have to create a pointless random string for Horde3D.

On the other hand, h3dCloneResource( ..., const char* name ) from egMain.cpp circumvents problems such as this entirely by using safeStr(name, 0) to generate a safe string in case nothing is entered (i.e. you can enter 0 for "name").

I have unified this behavior in my framework (simply by copying safeStr( name, 0 ) to the utils), but I'm not sure where to properly add this feature to the utils in the svn and need some help there.

[Edited for clarity]

Author:  johannes [ 23.06.2011, 12:57 ]
Post subject:  Re: safeStr in utils

Throw me a bone here. ;)

Am I just using h3dutCreateGeometryRes() etc. wrong and the behavior is expected?

I'd love to permanently and properly fix this, but now I'm not only unsure how to do so, but if it even applies.

Author:  marciano [ 24.06.2011, 07:57 ]
Post subject:  Re: safeStr in utils

The name that needs to be passed to h3dutCreateGeometryRes is the resource name/identifier which is required to reference the resource, for example from a material. This is just like for all other static resources. The function calls addResource which just increases the reference count in case the resource already exists.

It is not intended to call h3dutCreateGeometryRes if the resource already exists. We should add a check for that. If you want to change the resource data, you can either map the streams and upload new vertex data or if you need to completely recreate the resource because the number of vertices etc. changed, you can unload it first and then call h3dutCreateGeometryRes again.

The only thing safeStr does is making sure that a null pointer is interpreted as an empty string. h3dCloneResource can automatically create a unique name if an empty string is passed but this is a very special case.

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