Horde3D
http://horde3d.org/forums/

h3dRemoveNode not decrementing reference count?!
http://horde3d.org/forums/viewtopic.php?f=3&t=1655
Page 1 of 1

Author:  Christoph [ 21.03.2012, 11:51 ]
Post subject:  h3dRemoveNode not decrementing reference count?!

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

Author:  marciano [ 24.03.2012, 22:52 ]
Post subject:  Re: h3dRemoveNode not decrementing reference count?!

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?

Author:  Christoph [ 28.03.2012, 16:01 ]
Post subject:  Re: h3dRemoveNode not decrementing reference count?!

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()?

Author:  Volker [ 28.03.2012, 17:08 ]
Post subject:  Re: h3dRemoveNode not decrementing reference count?!

Christoph wrote:
So for each h3dAddResource(), there has to be an h3dRemoveResource()?

Exactly

Author:  Christoph [ 01.04.2012, 13:03 ]
Post subject:  Re: h3dRemoveNode not decrementing reference count?!

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

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