[dali_2.3.24] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / bubble-effect / bubble-emitter-impl.cpp
index dde8253..12b7a13 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 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.
@@ -131,7 +131,7 @@ BubbleEmitter::BubbleEmitter(const Vector2& movementArea,
     mNumRenderer          = 1;
   }
 
-  mRandomSeed = time(NULL);
+  mRandomSeed = static_cast<uint32_t>(time(NULL));
 }
 
 BubbleEmitter::~BubbleEmitter()
@@ -213,7 +213,7 @@ void BubbleEmitter::SetBackground(Texture bgTexture, const Vector3& hsvDelta)
 
   //Create renderer
   Dali::Geometry geometry   = CreateTexturedQuad();
-  Shader         shader     = Shader::New(SHADER_BUBBLE_EMITTER_VERT, SHADER_BUBBLE_EMITTER_FRAG);
+  Shader         shader     = Shader::New(SHADER_BUBBLE_EMITTER_VERT, SHADER_BUBBLE_EMITTER_FRAG, Shader::Hint::NONE, "BUBBLE_EMITTER");
   Renderer       renderer   = Renderer::New(geometry, shader);
   TextureSet     textureSet = TextureSet::New();
   textureSet.SetTexture(0u, bgTexture);
@@ -351,11 +351,14 @@ void BubbleEmitter::SetBubbleParameter(BubbleRenderer& bubbleRenderer, unsigned
 {
   Vector2 dir(direction);
 
-  int halfRange = displacement.x / 2;
+  int rangeX = std::max(static_cast<int>(displacement.x), 1); // To avoid divide by zero issue.
+  int rangeY = std::max(static_cast<int>(displacement.y), 1); // To avoid divide by zero issue.
+
+  int halfRangeX = displacement.x / 2;
   // for the y coordinate, always negative, so bubbles always go upwards
-  Vector2 randomVec(rand_r(&mRandomSeed) % static_cast<int>(displacement.x) - halfRange, -rand_r(&mRandomSeed) % static_cast<int>(displacement.y));
+  Vector2 randomVec(rand_r(&mRandomSeed) % rangeX - halfRangeX, -rand_r(&mRandomSeed) % rangeY);
   dir.Normalize();
-  randomVec.x -= dir.x * halfRange;
+  randomVec.x -= dir.x * halfRangeX;
   randomVec.y *= 1.0f - fabsf(dir.x) * 0.33f;
 
   if(randomVec.y > 0.0f)