diff --git a/core/Action/Animate.cpp b/core/Action/Animate.cpp index 1d9b10b6..2bf7e0fb 100644 --- a/core/Action/Animate.cpp +++ b/core/Action/Animate.cpp @@ -26,7 +26,7 @@ void e2d::Animate::setAnimation(Animation * animation) { if (animation && animation != _animation) { - SafeRelease(&_animation); + SafeRelease(_animation); _animation = animation; _animation->retain(); } @@ -90,7 +90,7 @@ void e2d::Animate::reset() void e2d::Animate::onDestroy() { Action::onDestroy(); - SafeRelease(&_animation); + SafeRelease(_animation); } e2d::Animate * e2d::Animate::clone() const diff --git a/core/Action/Loop.cpp b/core/Action/Loop.cpp index e5a6cd59..4065ec5b 100644 --- a/core/Action/Loop.cpp +++ b/core/Action/Loop.cpp @@ -81,7 +81,7 @@ void e2d::Loop::reset() void e2d::Loop::onDestroy() { Action::onDestroy(); - SafeRelease(&_action); + SafeRelease(_action); } void e2d::Loop::_resetTime() diff --git a/core/Action/Sequence.cpp b/core/Action/Sequence.cpp index abf95430..2be812dc 100644 --- a/core/Action/Sequence.cpp +++ b/core/Action/Sequence.cpp @@ -35,7 +35,7 @@ void e2d::Sequence::onDestroy() Action::onDestroy(); for (auto action : _actions) { - SafeRelease(&action); + SafeRelease(action); } } diff --git a/core/Action/Spawn.cpp b/core/Action/Spawn.cpp index d442322c..741509e3 100644 --- a/core/Action/Spawn.cpp +++ b/core/Action/Spawn.cpp @@ -32,7 +32,7 @@ void e2d::Spawn::onDestroy() Action::onDestroy(); for (auto action : _actions) { - SafeRelease(&action); + SafeRelease(action); } } diff --git a/core/Base/Input.cpp b/core/Base/Input.cpp index 2dd4ad7c..d29f1ad4 100644 --- a/core/Base/Input.cpp +++ b/core/Base/Input.cpp @@ -89,9 +89,9 @@ void Input::__uninit() if (s_MouseDevice) s_MouseDevice->Unacquire(); - SafeReleaseInterface(&s_MouseDevice); - SafeReleaseInterface(&s_KeyboardDevice); - SafeReleaseInterface(&s_pDirectInput); + SafeReleaseInterface(s_MouseDevice); + SafeReleaseInterface(s_KeyboardDevice); + SafeReleaseInterface(s_pDirectInput); } void e2d::Input::__update() diff --git a/core/Base/Renderer.cpp b/core/Base/Renderer.cpp index 4787a78b..2d86e693 100644 --- a/core/Base/Renderer.cpp +++ b/core/Base/Renderer.cpp @@ -133,20 +133,20 @@ bool e2d::Renderer::__createDeviceResources() void e2d::Renderer::__discardDeviceResources() { - SafeReleaseInterface(&s_pRenderTarget); - SafeReleaseInterface(&s_pSolidBrush); - SafeReleaseInterface(&s_pTextRenderer); + SafeReleaseInterface(s_pRenderTarget); + SafeReleaseInterface(s_pSolidBrush); + SafeReleaseInterface(s_pTextRenderer); } void e2d::Renderer::__discardResources() { - SafeReleaseInterface(&s_pTextFormat); - SafeReleaseInterface(&s_pDirect2dFactory); - SafeReleaseInterface(&s_pRenderTarget); - SafeReleaseInterface(&s_pSolidBrush); - SafeReleaseInterface(&s_pTextRenderer); - SafeReleaseInterface(&s_pIWICFactory); - SafeReleaseInterface(&s_pDWriteFactory); + SafeReleaseInterface(s_pTextFormat); + SafeReleaseInterface(s_pDirect2dFactory); + SafeReleaseInterface(s_pRenderTarget); + SafeReleaseInterface(s_pSolidBrush); + SafeReleaseInterface(s_pTextRenderer); + SafeReleaseInterface(s_pIWICFactory); + SafeReleaseInterface(s_pDWriteFactory); } void e2d::Renderer::__render() @@ -206,7 +206,7 @@ void e2d::Renderer::__render() pTextLayout->Draw(NULL, s_pTextRenderer, 10, 0); - SafeReleaseInterface(&pTextLayout); + SafeReleaseInterface(pTextLayout); } } diff --git a/core/Collider/Collider.cpp b/core/Collider/Collider.cpp index 74a5c0c2..844510b9 100644 --- a/core/Collider/Collider.cpp +++ b/core/Collider/Collider.cpp @@ -14,7 +14,7 @@ e2d::Collider::Collider() e2d::Collider::~Collider() { - SafeReleaseInterface(&_transformed); + SafeReleaseInterface(_transformed); } e2d::Node * e2d::Collider::getParentNode() const @@ -90,7 +90,7 @@ void e2d::Collider::_transform() } // 释放原碰撞体 - SafeReleaseInterface(&_transformed); + SafeReleaseInterface(_transformed); // 根据父节点转换几何图形 Renderer::getID2D1Factory()->CreateTransformedGeometry( diff --git a/core/Collider/ColliderCircle.cpp b/core/Collider/ColliderCircle.cpp index 8209b1c7..eaee238e 100644 --- a/core/Collider/ColliderCircle.cpp +++ b/core/Collider/ColliderCircle.cpp @@ -27,12 +27,12 @@ e2d::ColliderCircle::ColliderCircle(Node * node) e2d::ColliderCircle::~ColliderCircle() { - SafeReleaseInterface(&_d2dCircle); + SafeReleaseInterface(_d2dCircle); } void e2d::ColliderCircle::setCircle(Point center, double radius) { - SafeReleaseInterface(&_d2dCircle); + SafeReleaseInterface(_d2dCircle); Renderer::getID2D1Factory()->CreateEllipseGeometry( D2D1::Ellipse( diff --git a/core/Collider/ColliderEllipse.cpp b/core/Collider/ColliderEllipse.cpp index ef9b4663..8c42d46c 100644 --- a/core/Collider/ColliderEllipse.cpp +++ b/core/Collider/ColliderEllipse.cpp @@ -27,12 +27,12 @@ e2d::ColliderEllipse::ColliderEllipse(Node * node) e2d::ColliderEllipse::~ColliderEllipse() { - SafeReleaseInterface(&_d2dEllipse); + SafeReleaseInterface(_d2dEllipse); } void e2d::ColliderEllipse::setEllipse(Point center, double radiusX, double radiusY) { - SafeReleaseInterface(&_d2dEllipse); + SafeReleaseInterface(_d2dEllipse); Renderer::getID2D1Factory()->CreateEllipseGeometry( D2D1::Ellipse( diff --git a/core/Collider/ColliderRect.cpp b/core/Collider/ColliderRect.cpp index 1bd0d341..28d7ef23 100644 --- a/core/Collider/ColliderRect.cpp +++ b/core/Collider/ColliderRect.cpp @@ -20,12 +20,12 @@ e2d::ColliderRect::ColliderRect(Node * node) e2d::ColliderRect::~ColliderRect() { - SafeReleaseInterface(&_d2dRectangle); + SafeReleaseInterface(_d2dRectangle); } void e2d::ColliderRect::setRect(double left, double top, double right, double bottom) { - SafeReleaseInterface(&_d2dRectangle); + SafeReleaseInterface(_d2dRectangle); Renderer::getID2D1Factory()->CreateRectangleGeometry( D2D1::RectF( diff --git a/core/Common/Animation.cpp b/core/Common/Animation.cpp index f4a62288..7b5ffd3a 100644 --- a/core/Common/Animation.cpp +++ b/core/Common/Animation.cpp @@ -35,7 +35,7 @@ void e2d::Animation::onDestroy() { for (auto frame : _frames) { - SafeRelease(&frame); + SafeRelease(frame); } } diff --git a/core/Common/Image.cpp b/core/Common/Image.cpp index 8f00af26..f817a90d 100644 --- a/core/Common/Image.cpp +++ b/core/Common/Image.cpp @@ -227,10 +227,10 @@ bool e2d::Image::preload(const String& fileName) } // 释放相关资源 - SafeReleaseInterface(&pDecoder); - SafeReleaseInterface(&pSource); - SafeReleaseInterface(&pStream); - SafeReleaseInterface(&pConverter); + SafeReleaseInterface(pDecoder); + SafeReleaseInterface(pSource); + SafeReleaseInterface(pStream); + SafeReleaseInterface(pConverter); return SUCCEEDED(hr); } @@ -352,11 +352,11 @@ bool e2d::Image::preload(int resNameId, const String& resType) } // 释放相关资源 - SafeReleaseInterface(&pDecoder); - SafeReleaseInterface(&pSource); - SafeReleaseInterface(&pStream); - SafeReleaseInterface(&pConverter); - SafeReleaseInterface(&pScaler); + SafeReleaseInterface(pDecoder); + SafeReleaseInterface(pSource); + SafeReleaseInterface(pStream); + SafeReleaseInterface(pConverter); + SafeReleaseInterface(pScaler); return SUCCEEDED(hr); } @@ -366,13 +366,13 @@ void e2d::Image::clearCache() { for (auto bitmap : s_mBitmapsFromFile) { - SafeReleaseInterface(&bitmap.second); + SafeReleaseInterface(bitmap.second); } s_mBitmapsFromFile.clear(); for (auto bitmap : s_mBitmapsFromResource) { - SafeReleaseInterface(&bitmap.second); + SafeReleaseInterface(bitmap.second); } s_mBitmapsFromResource.clear(); } diff --git a/core/Common/Scene.cpp b/core/Common/Scene.cpp index 57ce530e..377878cb 100644 --- a/core/Common/Scene.cpp +++ b/core/Common/Scene.cpp @@ -89,5 +89,5 @@ void e2d::Scene::showCollider(bool visiable) void e2d::Scene::onDestroy() { - SafeRelease(&_root); + SafeRelease(_root); } diff --git a/core/Custom/CustomTextRenderer.cpp b/core/Custom/CustomTextRenderer.cpp index e85e302c..e012d9c3 100644 --- a/core/Custom/CustomTextRenderer.cpp +++ b/core/Custom/CustomTextRenderer.cpp @@ -25,9 +25,9 @@ CustomTextRenderer::CustomTextRenderer( CustomTextRenderer::~CustomTextRenderer() { - SafeReleaseInterface(&pD2DFactory_); - SafeReleaseInterface(&pRT_); - SafeReleaseInterface(&pBrush_); + SafeReleaseInterface(pD2DFactory_); + SafeReleaseInterface(pRT_); + SafeReleaseInterface(pBrush_); } STDMETHODIMP_(void) CustomTextRenderer::SetTextStyle( @@ -146,9 +146,9 @@ STDMETHODIMP CustomTextRenderer::DrawGlyphRun( ); } - SafeReleaseInterface(&pPathGeometry); - SafeReleaseInterface(&pSink); - SafeReleaseInterface(&pTransformedGeometry); + SafeReleaseInterface(pPathGeometry); + SafeReleaseInterface(pSink); + SafeReleaseInterface(pTransformedGeometry); return hr; } @@ -233,8 +233,8 @@ STDMETHODIMP CustomTextRenderer::DrawUnderline( ); } - SafeReleaseInterface(&pRectangleGeometry); - SafeReleaseInterface(&pTransformedGeometry); + SafeReleaseInterface(pRectangleGeometry); + SafeReleaseInterface(pTransformedGeometry); return S_OK; } @@ -319,8 +319,8 @@ STDMETHODIMP CustomTextRenderer::DrawStrikethrough( ); } - SafeReleaseInterface(&pRectangleGeometry); - SafeReleaseInterface(&pTransformedGeometry); + SafeReleaseInterface(pRectangleGeometry); + SafeReleaseInterface(pTransformedGeometry); return S_OK; } diff --git a/core/Manager/ActionManager.cpp b/core/Manager/ActionManager.cpp index 2abbea6d..aa6f800a 100644 --- a/core/Manager/ActionManager.cpp +++ b/core/Manager/ActionManager.cpp @@ -166,7 +166,7 @@ void e2d::ActionManager::__clearAllBindedWith(Node * target) auto a = s_vRunningActions[i]; if (a->getTarget() == target) { - SafeRelease(&a); + SafeRelease(a); s_vRunningActions.erase(s_vRunningActions.begin() + i); } else @@ -181,7 +181,7 @@ void e2d::ActionManager::__uninit() { for (auto action : s_vRunningActions) { - SafeRelease(&action); + SafeRelease(action); } s_vActions.clear(); s_vRunningActions.clear(); diff --git a/core/Manager/ColliderManager.cpp b/core/Manager/ColliderManager.cpp index f9fa83fe..74cbe03e 100644 --- a/core/Manager/ColliderManager.cpp +++ b/core/Manager/ColliderManager.cpp @@ -246,7 +246,7 @@ void e2d::ColliderManager::__removeCollider(Collider * pCollider) { if (s_vColliders[i] == pCollider) { - SafeRelease(&pCollider); + SafeRelease(pCollider); s_vColliders.erase(s_vColliders.begin() + i); return; } diff --git a/core/Manager/SceneManager.cpp b/core/Manager/SceneManager.cpp index b299997e..5092e83e 100644 --- a/core/Manager/SceneManager.cpp +++ b/core/Manager/SceneManager.cpp @@ -68,7 +68,7 @@ void e2d::SceneManager::clear() while (s_SceneStack.size()) { auto temp = s_SceneStack.top(); - SafeRelease(&temp); + SafeRelease(temp); s_SceneStack.pop(); } } @@ -127,7 +127,7 @@ void e2d::SceneManager::__update() } else { - SafeRelease(&s_pCurrScene); + SafeRelease(s_pCurrScene); } // 执行下一场景的 onEnter 函数 @@ -172,8 +172,8 @@ bool e2d::SceneManager::__init() void e2d::SceneManager::__uninit() { - SafeRelease(&s_pCurrScene); - SafeRelease(&s_pNextScene); - SafeRelease(&s_pTransition); + SafeRelease(s_pCurrScene); + SafeRelease(s_pNextScene); + SafeRelease(s_pTransition); SceneManager::clear(); } diff --git a/core/Node/Node.cpp b/core/Node/Node.cpp index 72f9b04b..bd4041d2 100644 --- a/core/Node/Node.cpp +++ b/core/Node/Node.cpp @@ -896,7 +896,7 @@ bool e2d::Node::isPointIn(Point point) const &ret ); // 删除临时创建的碰撞体 - SafeReleaseInterface(&rect); + SafeReleaseInterface(rect); } if (ret) @@ -950,9 +950,9 @@ bool e2d::Node::isIntersectWith(const Node * node) const &relation ); // 删除临时创建的碰撞体 - SafeReleaseInterface(&pRect1); - SafeReleaseInterface(&pRect2); - SafeReleaseInterface(&pCollider); + SafeReleaseInterface(pRect1); + SafeReleaseInterface(pRect2); + SafeReleaseInterface(pCollider); if ((relation != D2D1_GEOMETRY_RELATION_UNKNOWN) && (relation != D2D1_GEOMETRY_RELATION_DISJOINT)) { @@ -985,7 +985,7 @@ void e2d::Node::onDestroy() ColliderManager::__removeCollider(_collider); for (auto child : _children) { - SafeRelease(&child); + SafeRelease(child); } } diff --git a/core/Node/Sprite.cpp b/core/Node/Sprite.cpp index 63da8082..dc83f111 100644 --- a/core/Node/Sprite.cpp +++ b/core/Node/Sprite.cpp @@ -46,7 +46,7 @@ bool e2d::Sprite::open(Image * image) { if (image) { - SafeRelease(&_image); + SafeRelease(_image); _image = image; _image->retain(); @@ -128,5 +128,5 @@ void e2d::Sprite::onRender() void e2d::Sprite::onDestroy() { Node::onDestroy(); - SafeRelease(&_image); + SafeRelease(_image); } diff --git a/core/Node/Text.cpp b/core/Node/Text.cpp index b8e4d18f..7509c695 100644 --- a/core/Node/Text.cpp +++ b/core/Node/Text.cpp @@ -76,8 +76,8 @@ e2d::Text::Text( e2d::Text::~Text() { - SafeReleaseInterface(&_textFormat); - SafeReleaseInterface(&_textLayout); + SafeReleaseInterface(_textFormat); + SafeReleaseInterface(_textLayout); } e2d::String e2d::Text::getText() const @@ -313,7 +313,7 @@ void e2d::Text::_reset() void e2d::Text::_createFormat() { - SafeReleaseInterface(&_textFormat); + SafeReleaseInterface(_textFormat); HRESULT hr = Renderer::getIDWriteFactory()->CreateTextFormat( _style.fontFamily, @@ -359,7 +359,7 @@ void e2d::Text::_createFormat() void e2d::Text::_createLayout() { - SafeReleaseInterface(&_textLayout); + SafeReleaseInterface(_textLayout); // 文本为空字符串时,重置属性 if (_text.isEmpty()) @@ -410,7 +410,7 @@ void e2d::Text::_createLayout() // 重设文本宽高 this->setSize(metrics.width, metrics.height); // 重新创建 layout - SafeReleaseInterface(&_textLayout); + SafeReleaseInterface(_textLayout); hr = Renderer::getIDWriteFactory()->CreateTextLayout(_text, length, _textFormat, _width, 0, &_textLayout); } } diff --git a/core/Tool/Music.cpp b/core/Tool/Music.cpp index 2edacd74..aa6502b3 100644 --- a/core/Tool/Music.cpp +++ b/core/Tool/Music.cpp @@ -816,7 +816,7 @@ bool e2d::Music::__init() if (FAILED(hr = s_pXAudio2->CreateMasteringVoice(&s_pMasteringVoice))) { WARN_IF(true, "Failed creating mastering voice"); - e2d::SafeReleaseInterface(&s_pXAudio2); + e2d::SafeReleaseInterface(s_pXAudio2); return false; } @@ -838,5 +838,5 @@ void e2d::Music::__uninit() s_pMasteringVoice->DestroyVoice(); } - e2d::SafeReleaseInterface(&s_pXAudio2); + e2d::SafeReleaseInterface(s_pXAudio2); } diff --git a/core/Transition/Transition.cpp b/core/Transition/Transition.cpp index 8b68ac94..8753e682 100644 --- a/core/Transition/Transition.cpp +++ b/core/Transition/Transition.cpp @@ -18,8 +18,8 @@ e2d::Transition::Transition(double duration) e2d::Transition::~Transition() { - SafeReleaseInterface(&_outLayer); - SafeReleaseInterface(&_inLayer); + SafeReleaseInterface(_outLayer); + SafeReleaseInterface(_inLayer); } bool e2d::Transition::isDone() @@ -29,8 +29,8 @@ bool e2d::Transition::isDone() void e2d::Transition::onDestroy() { - SafeRelease(&_outScene); - SafeRelease(&_inScene); + SafeRelease(_outScene); + SafeRelease(_inScene); } void e2d::Transition::_init(Scene * prev, Scene * next) diff --git a/core/e2dcommon.h b/core/e2dcommon.h index 0760ea32..58ab49b9 100644 --- a/core/e2dcommon.h +++ b/core/e2dcommon.h @@ -866,12 +866,12 @@ protected: template -inline void SafeRelease(Object** p) +inline void SafeRelease(Object*& p) { - if (*p) + if (p != nullptr) { - (*p)->release(); - (*p) = nullptr; + p->release(); + p = nullptr; } } diff --git a/core/e2dcustom.h b/core/e2dcustom.h index 365332ac..d82ed664 100644 --- a/core/e2dcustom.h +++ b/core/e2dcustom.h @@ -4,12 +4,12 @@ namespace e2d { template - inline void SafeReleaseInterface(Interface **pp) - { - if (*pp != nullptr) - { - (*pp)->Release(); - (*pp) = nullptr; + inline void SafeReleaseInterface(Interface*& p) + { + if (p != nullptr) + { + p->Release(); + p = nullptr; } } diff --git a/project/vs2017/Easy2D.vcxproj b/project/vs2017/Easy2D.vcxproj index 6f0b6912..e7723655 100644 --- a/project/vs2017/Easy2D.vcxproj +++ b/project/vs2017/Easy2D.vcxproj @@ -101,7 +101,7 @@ Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) false - EditAndContinue + None false true