Problem about AddRef()

Started by
1 comment, last by dave 18 years, 1 month ago
pSkinInfo = pSkinInfoIn; pSkinInfo->AddRef(); anim_pOriginalMesh = pMesh; anim_pOriginalMesh->AddRef(); Error occurred when I omitted to add the "->AddRef()" And I found that anim_pOriginalMesh = pMesh; pMesh->AddRef(); is the same as anim_pOriginalMesh = pMesh; anim_pOriginalMesh->AddRef(); why? Are they just represent a link was added?
Advertisement
I'll move this over to General Programming - despite being DX related it's more of a general COM programming issue

AddRef() is a way of indicating that some code/module/program wants to make use of that particular object, but understands that other components may also be wanting to use it - yet you don't want the other person deleting it whilst you're still using it. Thus COM objects only get "properly" destroyed when the reference count is 0 - indicating that no one is interested in using it.

The finer details of COM weren't something I chose to spend much time with, but hopefully someone else can provide you with a better answer [smile]

Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

In my experience you don't get run time errors by not managing reference counting properly, but only if the SDK is in Debug mode will you get anything, usually at the end of execution.

With that second example pMesh and anim_pOriginalMesh are pointers to the same object so it doesn't matter which one you use. Don't forget that you are requesting for a resource, which D3D allocates somewhere, then assigning one pointer to another, so they both point at it. Then you have to addref to tell D3D that you are using it in two places.

Dave

This topic is closed to new replies.

Advertisement