-
Notifications
You must be signed in to change notification settings - Fork 117
refactor(w3dview): Migrate from MEMBER_ADD/MEMBER_RELEASE macros to RefCountPtr<T> #1763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
refactor(w3dview): Migrate from MEMBER_ADD/MEMBER_RELEASE macros to RefCountPtr<T> #1763
Conversation
cc1d8dc to
c3f8d36
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before I continue review, please make another pass on this and correct all missing resource cleanups. It is important that no logic is changed, unless it fixes a bug.
Core/Tools/W3DView/W3DViewDoc.cpp
Outdated
|
|
||
| // Was there a valid display object? | ||
| if (m_pCRenderObj) | ||
| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition above is obsoleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, yes the operations inside are safe to execute regardless. If I understand correctly, the conditional checks make the intent explicit (only cleanup when there's something to clean up). RefCountPtr provides operator const DummyPtrType *() specifically to enable null-checking in boolean contexts.
// From ref_ptr.h documentation (lines 92-96):
void Do_It(void)
{
if (MyObject) { // Recommended pattern
MyObject->Do_Something();
}
}
This is also the pattern we use elsewhere eg CW3DViewDoc::CleanupResources.
Happy to keep or remove them, up to you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment functions already do the tests and are safe.
GeneralsGameCode/Core/Libraries/Source/WWVegas/WWLib/ref_ptr.h
Lines 289 to 298 in 7a6402b
| const RefCountPtr<T> & operator =(DummyPtrType * dummy_ptr) | |
| { | |
| if (Referent) { | |
| Referent->Release_Ref(); | |
| } | |
| Referent = 0; | |
| return *this; | |
| } |
Alternatively, use Clear() function. Maybe that is cleaner.
GeneralsGameCode/Core/Libraries/Source/WWVegas/WWLib/ref_ptr.h
Lines 352 to 358 in 7a6402b
| void Clear(void) | |
| { | |
| if (Referent) { | |
| Referent->Release_Ref(); | |
| Referent = 0; | |
| } | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like Clear :) Done
c3f8d36 to
0cbd2fc
Compare
…o RefCountPtr<T> Replace MEMBER_ADD/MEMBER_RELEASE macros with RefCountPtr<T> smart pointers. - AssetInfo: m_pRenderObj now RefCountPtr<RenderObjClass> - ScreenCursor: m_pTexture and m_pVertMaterial now RefCountPtr - PlaySoundDialog: SoundObj now RefCountPtr<AudibleSoundClass>
Replace MEMBER_ADD/MEMBER_RELEASE macros with RefCountPtr<T> smart pointers. - SpherePropertySheet: m_RenderObj now RefCountPtr<SphereRenderObjClass> - RingPropertySheet: m_RenderObj now RefCountPtr<RingRenderObjClass> - EmitterPropertySheet: local emitter variables use REF_PTR_RELEASE - EmitterInstanceList: use REF_PTR_RELEASE for vector cleanup
Replace MEMBER_ADD/MEMBER_RELEASE macros with RefCountPtr<T> and REF_PTR_RELEASE. - W3DViewDoc: m_pCRenderObj, m_pCAnimation, m_pCursorScene, m_pCursor now RefCountPtr - GraphicView: m_pCamera and m_pLightMesh now RefCountPtr - Local variables in Utils, DataTreeView, BoneMgrDialog, etc. use REF_PTR_RELEASE
Remove obsolete macros now replaced by RefCountPtr<T> and core library macros. - Removed: MEMBER_ADD, MEMBER_RELEASE, SAFE_ADD_REF, SAFE_RELEASE_REF - Kept: SAFE_DELETE, SAFE_DELETE_ARRAY, COM_RELEASE, SAFE_CLOSE, SANITY_CHECK
…rScene in CleanupResources
0cbd2fc to
4c2acf0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we first make a change where we just remove the duplicate Macros, without adding RefCountPtr? Then this change will be simpler? And then make small changes to introduce RefCountPtr slowly? I am afraid this will be a big review here otherwise given the implications. One mistake with ref counting and the game will crash.
| m_pCursor->Remove (); | ||
| } | ||
| MEMBER_RELEASE (m_pCursorScene); | ||
| m_pCursor.Clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This clear is wrong.
| // Remove this object from the scene | ||
| Remove_Object_From_Scene (m_pCRenderObj.Peek()); | ||
| } | ||
| m_pCRenderObj.Clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be moved into scope above.
| m_pCRenderObj = NULL; | ||
| Remove_Object_From_Scene (m_pCRenderObj.Peek()); | ||
| } | ||
| m_pCRenderObj.Clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be moved into scope above
| { | ||
| // Lose the animation | ||
| SAFE_DELETE (m_pCAnimCombo); | ||
| MEMBER_RELEASE (m_pCAnimation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong.
| MEMBER_RELEASE (m_pCAnimation); | ||
| m_pCAnimation = WW3DAssetManager::Get_Instance()->Get_HAnim (pszAnimationName); | ||
| m_pCAnimation = RefCountPtr<HAnimClass>::Create_NoAddRef(WW3DAssetManager::Get_Instance()->Get_HAnim (pszAnimationName)); | ||
| ASSERT (m_pCAnimation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.Peek()
Multiple times in this change. Please check what's up with ASSERT.
Ok, check out 1784. Shall we continue this PR after rebasing and have it focus just on just W3DView, then additional RefCountPtr migrations can have separate PRs? |
Replaces custom reference counting macros (MEMBER_ADD, MEMBER_RELEASE, SAFE_ADD_REF, SAFE_RELEASE_REF) with the type-safe RefCountPtr smart pointer from the core library.
Member Variables Migrated to RefCountPtr:
Local Variable Usage:
Removed Macros (Utils.h):
Notes: