From 50d750707173c768f02a3a7595e9025e61befbc0 Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Thu, 18 Apr 2024 12:01:01 +0900 Subject: [PATCH] Do not call RemoveObserver when we don't add it for PropertyResetter It is possible that PropertyResetter destructed before Initialize() when app terminate case. If then, it is possible to got some crash when we try to access to 'destroyed' property owner, and call RemoveObserver(); To avoid this case, let we make ensure that we call initalized so it is possible to call RemoveObserver(). Change-Id: I24b74f1d963090d867e1d047fe739132f9465ee3 Signed-off-by: Eunki, Hong --- dali/internal/update/common/property-resetter.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/dali/internal/update/common/property-resetter.h b/dali/internal/update/common/property-resetter.h index 833be60..8b68fbf 100644 --- a/dali/internal/update/common/property-resetter.h +++ b/dali/internal/update/common/property-resetter.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_SCENEGRAPH_PROPERTY_RESETTER_H /* - * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,9 +46,12 @@ public: */ ~PropertyResetterBase() override { - if(mPropertyOwner != nullptr) + if(DALI_LIKELY(mInitialized)) { - mPropertyOwner->RemoveObserver(*this); + if(mPropertyOwner != nullptr) + { + mPropertyOwner->RemoveObserver(*this); + } } } @@ -59,6 +62,9 @@ public: */ void Initialize() { + DALI_ASSERT_ALWAYS(!mInitialized && "Dont call PropertyResetterBase::Initialize() twice"); + + mInitialized = true; mPropertyOwner->AddObserver(*this); mPropertyOwner->SetUpdated(true); } @@ -162,6 +168,7 @@ protected: mBaseProperty(baseProperty), mRunning(ACTIVE), mActive(ACTIVE), + mInitialized(false), mDisconnected(false) { } @@ -170,7 +177,8 @@ protected: PropertyBase* mBaseProperty; ///< The base property being animated or constrained int8_t mRunning; ///< Used to determine if we should finish or not, 2 if running, 1 if aging, 0 if stopped int8_t mActive; ///< 2 if active, 1 if aging, 0 if stopped - bool mDisconnected; ///< True if the property owner has been disconnected + bool mInitialized : 1; + bool mDisconnected : 1; ///< True if the property owner has been disconnected }; class BakerResetter : public PropertyResetterBase -- 2.7.4