Sign in to follow this  

Problem about AddRef()

This topic is 4299 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 4299 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this