From: Eunki, Hong Date: Wed, 29 Nov 2023 01:43:19 +0000 (+0900) Subject: [Tizen] Fix crash when resize window during Animation mode X-Git-Tag: accepted/tizen/8.0/unified/20231130.180826^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=38f33d55cd2968d706eea210e8cf67d4e792cb8f;p=platform%2Fcore%2Fuifw%2Fdali-demo.git [Tizen] Fix crash when resize window during Animation mode When we are running on animation ball, mPhysicsAdaptor don't have body. If then, when we resize the window, it will be asserted Change-Id: I2c71a2b1e845d7257f581fcc41f997794ee78fa5 Signed-off-by: Eunki, Hong --- diff --git a/examples/benchmark-2dphysics/benchmark-2d-physics-controller.cpp b/examples/benchmark-2dphysics/benchmark-2d-physics-controller.cpp index 2926d5c72..190549a17 100644 --- a/examples/benchmark-2dphysics/benchmark-2d-physics-controller.cpp +++ b/examples/benchmark-2dphysics/benchmark-2d-physics-controller.cpp @@ -62,6 +62,12 @@ const cpBitmask COLLISION_MASK{0xfF}; const cpBitmask BALL_COLLIDES_WITH{BALL_GROUP | BOUNDS_GROUP}; +enum BenchmarkType +{ + ANIMATION, + PHYSICS_2D, +}; + /** * @brief The physics demo using Chipmunk2D APIs. */ @@ -86,13 +92,33 @@ public: mWindow.GetRootLayer().TouchedSignal().Connect(this, &Physics2dBenchmarkController::OnTouched); mWindow.SetBackgroundColor(Color::DARK_SLATE_GRAY); - CreateAnimationSimulation(); + mType = BenchmarkType::ANIMATION; + + CreateSimulation(); mTimer = Timer::New(ANIMATION_TIME); mTimer.TickSignal().Connect(this, &Physics2dBenchmarkController::AnimationSimFinished); mTimer.Start(); } + void CreateSimulation() + { + switch(mType) + { + case BenchmarkType::ANIMATION: + default: + { + CreateAnimationSimulation(); + break; + } + case BenchmarkType::PHYSICS_2D: + { + CreatePhysicsSimulation(); + break; + } + } + } + void CreateAnimationSimulation() { Window::WindowSize windowSize = mWindow.GetSize(); @@ -154,19 +180,26 @@ public: bool AnimationSimFinished() { - static bool first = true; - if(first) + switch(mType) { - UnparentAndReset(mAnimationSimRootActor); - mBallAnimation.Stop(); - mBallAnimation.Clear(); - first = false; + case BenchmarkType::ANIMATION: + default: + { + UnparentAndReset(mAnimationSimRootActor); + mBallAnimation.Stop(); + mBallAnimation.Clear(); - CreatePhysicsSimulation(); - return true; - } + mType = BenchmarkType::PHYSICS_2D; - mApplication.Quit(); + CreateSimulation(); + return true; + } + case BenchmarkType::PHYSICS_2D: + { + mApplication.Quit(); + break; + } + } return false; } @@ -189,7 +222,7 @@ public: auto actor = Actor::DownCast(source.GetTarget()); if(actor) { - int index = actor["index"]; + int index = actor["index"]; mBallVelocity[index].x = fabsf(mBallVelocity[index].x); ContinueAnimation(); } @@ -200,7 +233,7 @@ public: auto actor = Actor::DownCast(source.GetTarget()); if(actor) { - int index = actor["index"]; + int index = actor["index"]; mBallVelocity[index].x = -fabsf(mBallVelocity[index].x); ContinueAnimation(); } @@ -211,7 +244,7 @@ public: auto actor = Actor::DownCast(source.GetTarget()); if(actor) { - int index = actor["index"]; + int index = actor["index"]; mBallVelocity[index].y = -fabsf(mBallVelocity[index].y); ContinueAnimation(); } @@ -222,7 +255,7 @@ public: auto actor = Actor::DownCast(source.GetTarget()); if(actor) { - int index = actor["index"]; + int index = actor["index"]; mBallVelocity[index].y = fabsf(mBallVelocity[index].y); ContinueAnimation(); } @@ -339,15 +372,32 @@ public: void OnTerminate(Application& application) { + UnparentAndReset(mAnimationSimRootActor); UnparentAndReset(mPhysicsRoot); } void OnWindowResize(Window window, Window::WindowSize newSize) { - auto scopedAccessor = mPhysicsAdaptor.GetPhysicsAccessor(); - cpSpace* space = scopedAccessor->GetNative().Get(); - - CreateBounds(space, newSize); + switch(mType) + { + case BenchmarkType::ANIMATION: + default: + { + // TODO : Implement here if you want. + break; + } + case BenchmarkType::PHYSICS_2D: + { + if(mPhysicsAdaptor) + { + auto scopedAccessor = mPhysicsAdaptor.GetPhysicsAccessor(); + cpSpace* space = scopedAccessor->GetNative().Get(); + + CreateBounds(space, newSize); + } + break; + } + } } bool OnTouched(Dali::Actor actor, const Dali::TouchEvent& touch) @@ -371,6 +421,8 @@ private: Application& mApplication; Window mWindow; + BenchmarkType mType{BenchmarkType::ANIMATION}; + PhysicsAdaptor mPhysicsAdaptor; std::vector mBalls; Matrix mPhysicsTransform;