From 9b11fa4e91a371ac3d0d5ecd567dfd84503c6e01 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Fri, 15 Dec 2023 01:33:08 -0600 Subject: [PATCH] [olympic/keel] Fix some unsafe pointer accesses, disconnect signals on asset move --- src/olympic/keel/include/keel/assetmanager.hpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/olympic/keel/include/keel/assetmanager.hpp b/src/olympic/keel/include/keel/assetmanager.hpp index 294ccf30..d543ec3a 100644 --- a/src/olympic/keel/include/keel/assetmanager.hpp +++ b/src/olympic/keel/include/keel/assetmanager.hpp @@ -120,8 +120,8 @@ class AssetRef: public ox::SignalHandler { oxIgnoreError(m_ctr->updated.disconnectObject(this)); } m_ctr = h.m_ctr; - m_ctr->updated.connect(&updated, &ox::Signal::emitCheckError); if (m_ctr) { + m_ctr->updated.connect(&updated, &ox::Signal::emitCheckError); m_ctr->incRefs(); } return *this; @@ -136,7 +136,10 @@ class AssetRef: public ox::SignalHandler { oxIgnoreError(m_ctr->updated.disconnectObject(this)); } m_ctr = h.m_ctr; - m_ctr->updated.connect(this, &AssetRef::emitUpdated); + if (m_ctr) { + oxIgnoreError(m_ctr->updated.disconnectObject(&h)); + m_ctr->updated.connect(this, &AssetRef::emitUpdated); + } h.m_ctr = nullptr; return *this; } @@ -154,14 +157,13 @@ class AssetRef: public ox::SignalHandler { template constexpr AssetRef::AssetRef(AssetContainer const*c) noexcept: m_ctr(c) { - if (c) { - c->updated.connect(this, &AssetRef::emitUpdated); + if (m_ctr) { + m_ctr->updated.connect(this, &AssetRef::emitUpdated); } } template -constexpr AssetRef::AssetRef(AssetRef const&h) noexcept { - m_ctr = h.m_ctr; +constexpr AssetRef::AssetRef(AssetRef const&h) noexcept: m_ctr(h.m_ctr) { if (m_ctr) { m_ctr->updated.connect(this, &AssetRef::emitUpdated); m_ctr->incRefs(); @@ -171,7 +173,9 @@ constexpr AssetRef::AssetRef(AssetRef const&h) noexcept { template constexpr AssetRef::AssetRef(AssetRef &&h) noexcept { m_ctr = h.m_ctr; - m_ctr->updated.connect(this, &AssetRef::emitUpdated); + if (m_ctr) { + m_ctr->updated.connect(this, &AssetRef::emitUpdated); + } h.m_ctr = nullptr; }