Horde3D

Next-Generation Graphics Engine
It is currently 21.11.2024, 19:14

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: safeStr in utils
PostPosted: 12.06.2011, 14:28 
Offline

Joined: 22.06.2010, 19:21
Posts: 26
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]


Top
 Profile  
Reply with quote  
 Post subject: Re: safeStr in utils
PostPosted: 23.06.2011, 12:57 
Offline

Joined: 22.06.2010, 19:21
Posts: 26
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: safeStr in utils
PostPosted: 24.06.2011, 07:57 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group