Relayout only if the actor is on Scene
[platform/core/uifw/dali-core.git] / dali / internal / event / size-negotiation / relayout-controller-impl.cpp
index 653b20a..497f515 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
@@ -125,7 +125,15 @@ RelayoutController::~RelayoutController()
 
 RelayoutController* RelayoutController::Get()
 {
-  return &ThreadLocalStorage::Get().GetRelayoutController();
+  // There was crash when destroying actors and the ResizePolicy is USE_NATURAL_SIZE
+  // The ThreadLocalStorage::Get() only retrieve STL without checking if it exists.
+  // The caller of RelayoutController::Get() should check if RelayoutController is not null.
+  if(ThreadLocalStorage::Created())
+  {
+    return &ThreadLocalStorage::Get().GetRelayoutController();
+  }
+
+  return nullptr;
 }
 
 void RelayoutController::QueueActor(Internal::Actor* actor, RelayoutContainer& actors, Vector2 size)
@@ -438,17 +446,13 @@ void RelayoutController::Relayout()
         Actor& actorImpl = GetImplementation(actor);
         mRelayoutStack->PopBack();
 
-        if(actorImpl.RelayoutRequired())
+        if(actorImpl.RelayoutRequired() && actorImpl.OnScene())
         {
           DALI_LOG_INFO(gLogFilter, Debug::General, "[Internal::RelayoutController::Relayout] Negotiating %p %s %s (%.2f, %.2f)\n", &actorImpl, actor.GetTypeName().c_str(), actor.GetProperty<std::string>(Dali::Actor::Property::NAME).c_str(), size.width, size.height);
 
           // 3. Negotiate the size with the current actor. Pass it an empty container which the actor
           //    has to fill with all the actors it has not done any size negotiation for.
-
           actorImpl.NegotiateSize(size, *mRelayoutStack);
-
-          // Reset the flag so that size negotiation will respect the actor's original resize policy
-          actorImpl.SetUseAssignedSize(false);
         }
       }