Error: Bad reference counting?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Guest

Error: Bad reference counting?

Post by Guest »

I'm trying to use my own linked list class to manage objects in Irrlicht. The actual error message I get is an access violation error but it points me to an Irrlich header. A comment there claims I'm doing bad reference counting? I don't even know what that is. My linked list code is sound, I've used it before. Is there something I have to do when dynamically allocating nodes in Irrlicht? The error seems to occur only if I drop the nodes I create?
CZestmyr
Posts: 72
Joined: Sat Feb 12, 2005 7:11 pm
Location: Czech Republic
Contact:

Post by CZestmyr »

I think that you shouldn't drop() them before calling grab() on them in your list, which takes care of them. Calling drop() on them before any other class called grab() causes them to cease to exist, which causes problems, when you try to access their formal memory location.
Guest

Post by Guest »

I've never used grab(), do I call it when I create the node or just before I drop it? What does grab actually do for Irrlicht?

Thanks for the help, I'll try it and post back if I have any problems.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

I recommend looking at the documentation for ISceneManager and notice the difference between calls with add and create in their names, and what it says about drop().

The basic rule is : create functions don't grab() the object, add functions do.

So, If you call :

Code: Select all

anim = createXXXAnimator(...);
after a successful return from the function, the ref count of the animator is 1. Now, when you call

Code: Select all

node->addAnimator(anim);
This function for a node, will associate the animator with the node, and since the node relies on the animator's data, it will call grab() on the animator. So now, after a successful return from this function the animator's reference count is 2. If you no longer need the animator for anything else, you call drop() on it, so that when the sceneNode is done, and it calls drop on the animator( which it will, since it grabbed it ), the animtor will be destroyed and you don't have to worry about it.

There's tons of documentation about all of this. Look at IUnknown and ISceneManager.
Image
pfo
Posts: 370
Joined: Mon Aug 29, 2005 10:54 pm
Location: http://web.utk.edu/~pfox1

Post by pfo »

Out of curiousity, are you using memcpy on a struct with core::string? That was giving me a problem, when the first string frees it de-allocates the memory, when the copied string tries to free itself it tries to delete the same memory, causing the same problem you have.
Guest

Post by Guest »

don't grab() the object, add functions do
Yes it's true, but as far as I have understood, he wants to make some sort of his own scene manager.
Guest

Post by Guest »

So if I create an object using add, I just have to call:

SceneNode = smgr->addBillboardSceneNode(0, core::dimens...
...
SceneNode->remove();

to get rid of it and clean up all the memory it used?
Post Reply