Horde3D

Next-Generation Graphics Engine
It is currently 28.03.2024, 09:38

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: 21.03.2012, 11:51 
Offline

Joined: 09.02.2012, 22:38
Posts: 26
Hi,

I'm not sure if I've found a bug or if I've misunderstood the documentation. It seems that a GeometryRes's resource count gets increased by h3dAddModelNode() but not decreased by h3dRemoveNode(). If I manually decrement it, using h3dRemoveResource(), everything is fine. Thats odd.

Here is what I do (simplified):
1. res = h3dutCreateGeometryRes("GeometryName", ...);
2. model = h3dAddModelNode(..., res);
3. for each material: h3dAddMeshNode(model, ...);
... render several frames ...
4. h3dRemoveNode(model);
5. h3dReleaseUnusedResources();
6. Start again from 1. (since the number of vertices may change, I cannot update the resource using Map/Unmap).

The following assertion fails on the "second iteration" of my code.
h3dFindResource(H3DResTypes::Geometry, "GeometryName") == 0

If this isn't an implementation bug it's definitely a documentation one, since the resulting application bugs are non-obvious and hard to track down. So: which one is it? :)

Regards


Top
 Profile  
Reply with quote  
PostPosted: 24.03.2012, 22:52 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
Hi, I don't think that this is a bug. There's two types of references: internal references which are handled fully automatically by the engine and external/user references which require an explicit call of a release function. As you create a resource manually, you still hold a reference to it which needs to be released (h3dRemoveResource). The engine doesn't do this automatically because otherwise you might have a dangling handle.

Does everything work as expected if you release the resource explicitly?


Top
 Profile  
Reply with quote  
PostPosted: 28.03.2012, 16:01 
Offline

Joined: 09.02.2012, 22:38
Posts: 26
Yes, it does.

From documentation of h3dAddResource:
Quote:
This function tries to add a resource of a specified type and name to the resource manager. If a resource of the same type and name is already existing, the handle to the existing resource is returned instead of creating a new one and the user reference count of the resource is increased.

So its basically:
  • reference count = 1 if created (I thought it's reference count = 0)
  • reference count += 1 otherwise
So for each h3dAddResource(), there has to be an h3dRemoveResource()?


Top
 Profile  
Reply with quote  
PostPosted: 28.03.2012, 17:08 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
Christoph wrote:
So for each h3dAddResource(), there has to be an h3dRemoveResource()?

Exactly


Top
 Profile  
Reply with quote  
PostPosted: 01.04.2012, 13:03 
Offline

Joined: 09.02.2012, 22:38
Posts: 26
Patch:
Code:
Index: Horde3D.h
===================================================================
--- Horde3D.h   (revision 332)
+++ Horde3D.h   (working copy)
@@ -968,9 +968,10 @@
       Adds a resource.
    
    Details:
-      This function tries to add a resource of a specified type and name to the resource manager. If
-      a resource of the same type and name is already existing, the handle to the existing resource is returned
-      instead of creating a new one and the user reference count of the resource is increased.
+      This function tries to add a resource of a specified type and name to the resource manager. Each resource
+      holds a user reference count that initially equals one. If a resource of the same type and name already
+      exists, its user reference count is increased and a reference to the existing resource is returned.
+      This practically means that for each h3dAddResource() there has to be an corresponding h3dRemoveResource().
    
    Parameters:
       type   - type of the resource


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 29 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