Fix prevent issue - GetCurrent() might return null 19/41019/3
authorYoonsang Lee <ysang114.lee@samsung.com>
Thu, 11 Jun 2015 02:08:42 +0000 (11:08 +0900)
committerKimmo Hoikka <kimmo.hoikka@samsung.com>
Wed, 17 Jun 2015 15:42:06 +0000 (08:42 -0700)
- Internal::Stage::GetCurrent() might return null, so add null-checking
code

<Prevent message example>
[actor-impl.cpp]
2. returned_null: GetCurrent returns null. [show details]
CID 405268 (#1 of 1): Dereference null return value (NULL_RETURNS)
3. dereference: Dereferencing a pointer that might be null Dali::Internal::Stage::GetCurrent() when calling GetRenderTaskList. [show details]
1861    const RenderTaskList& taskList = Stage::GetCurrent()->GetRenderTaskList();

Change-Id: Icb306352a14c2660df89cb91261724d6f83b4983

dali/internal/event/actors/actor-impl.cpp
dali/internal/event/actors/camera-actor-impl.cpp
dali/internal/event/actors/layer-impl.cpp
dali/internal/event/animation/animation-impl.cpp
dali/internal/event/common/property-notification-impl.cpp
dali/internal/event/effects/shader-effect-impl.cpp
dali/internal/event/events/hit-test-algorithm-impl.cpp
dali/internal/event/modeling/animatable-mesh-impl.cpp
dali/internal/event/render-tasks/render-task-impl.cpp

index 2f48fed..64d3845 100644 (file)
@@ -1855,9 +1855,10 @@ DrawMode::Type Actor::GetDrawMode() const
 bool Actor::ScreenToLocal( float& localX, float& localY, float screenX, float screenY ) const
 {
   // only valid when on-stage
-  if( OnStage() )
+  StagePtr stage = Stage::GetCurrent();
+  if( stage && OnStage() )
   {
-    const RenderTaskList& taskList = Stage::GetCurrent()->GetRenderTaskList();
+    const RenderTaskList& taskList = stage->GetRenderTaskList();
 
     Vector2 converted( screenX, screenY );
 
index 8294fa3..7ee2ef1 100644 (file)
@@ -260,9 +260,10 @@ void CameraActor::SetPerspectiveProjection( const Size& size, const Vector2& ste
 
   if( Size::ZERO == size )
   {
-    if( Stage::IsInstalled() )
+    StagePtr stage = Stage::GetCurrent();
+    if( stage )
     {
-      const Size& stageSize = Stage::GetCurrent()->GetSize();
+      const Size& stageSize = stage->GetSize();
 
       width = stageSize.width;
       height = stageSize.height;
index 830384e..85a1a87 100644 (file)
@@ -227,10 +227,15 @@ void Layer::SetClippingBox(int x, int y, int width, int height)
 
     // Convert mClippingBox to GL based coordinates (from bottom-left)
     ClippingBox clippingBox( mClippingBox );
-    clippingBox.y = Stage::GetCurrent()->GetSize().height - clippingBox.y - clippingBox.height;
 
-    // layerNode is being used in a separate thread; queue a message to set the value
-    SetClippingBoxMessage( GetEventThreadServices(), GetSceneLayerOnStage(), clippingBox );
+    StagePtr stage = Stage::GetCurrent();
+    if( stage )
+    {
+      clippingBox.y = stage->GetSize().height - clippingBox.y - clippingBox.height;
+
+      // layerNode is being used in a separate thread; queue a message to set the value
+      SetClippingBoxMessage( GetEventThreadServices(), GetSceneLayerOnStage(), clippingBox );
+    }
   }
 }
 
index 1aa61e7..10ee3da 100644 (file)
@@ -90,20 +90,27 @@ AnimationPtr Animation::New(float durationSeconds)
 {
   Stage* stage = Stage::GetCurrent();
 
-  AnimationPlaylist& playlist = stage->GetAnimationPlaylist();
-
-  if( durationSeconds < 0.0f )
+  if( stage )
   {
-    DALI_LOG_WARNING("duration should be greater than 0.0f.\n");
-    durationSeconds = 0.0f;
-  }
+    AnimationPlaylist& playlist = stage->GetAnimationPlaylist();
+
+    if( durationSeconds < 0.0f )
+    {
+      DALI_LOG_WARNING("duration should be greater than 0.0f.\n");
+      durationSeconds = 0.0f;
+    }
 
-  AnimationPtr animation = new Animation( *stage, playlist, durationSeconds, DEFAULT_END_ACTION, DEFAULT_DISCONNECT_ACTION, DEFAULT_ALPHA_FUNCTION );
+    AnimationPtr animation = new Animation( *stage, playlist, durationSeconds, DEFAULT_END_ACTION, DEFAULT_DISCONNECT_ACTION, DEFAULT_ALPHA_FUNCTION );
 
-  // Second-phase construction
-  animation->Initialize();
+    // Second-phase construction
+    animation->Initialize();
 
-  return animation;
+    return animation;
+  }
+  else
+  {
+    return NULL;
+  }
 }
 
 Animation::Animation( EventThreadServices& eventThreadServices, AnimationPlaylist& playlist, float durationSeconds, EndAction endAction, EndAction disconnectAction, AlphaFunction defaultAlpha )
index ee87eb1..14536a1 100644 (file)
@@ -46,15 +46,21 @@ PropertyNotificationPtr PropertyNotification::New(Property& target,
 
   UpdateManager& updateManager = tls.GetUpdateManager();
 
-  PropertyNotificationManager& propertyNotificationManager = Stage::GetCurrent()->GetPropertyNotificationManager();
-
-  PropertyNotificationPtr propertyNotification = new PropertyNotification(updateManager,
-                                                                          propertyNotificationManager,
-                                                                          target,
-                                                                          componentIndex,
-                                                                          condition);
-
-  return propertyNotification;
+  StagePtr stage = Stage::GetCurrent();
+  if( stage )
+  {
+    PropertyNotificationManager& propertyNotificationManager = stage->GetPropertyNotificationManager();
+    PropertyNotificationPtr propertyNotification = new PropertyNotification(updateManager,
+                                                                            propertyNotificationManager,
+                                                                            target,
+                                                                            componentIndex,
+                                                                            condition);
+    return propertyNotification;
+  }
+  else
+  {
+    return NULL;
+  }
 }
 
 PropertyNotification::PropertyNotification( UpdateManager& updateManager,
index d808e39..fa51e6e 100644 (file)
@@ -199,10 +199,16 @@ ShaderEffectPtr ShaderEffect::New( Dali::ShaderEffect::GeometryHints hints )
 {
   Stage* stage = Stage::GetCurrent();
 
-  ShaderEffectPtr shaderEffect( new ShaderEffect( *stage, hints ) );
-  shaderEffect->RegisterObject();
-
-  return shaderEffect;
+  if( stage )
+  {
+    ShaderEffectPtr shaderEffect( new ShaderEffect( *stage, hints ) );
+    shaderEffect->RegisterObject();
+    return shaderEffect;
+  }
+  else
+  {
+    return NULL;
+  }
 }
 
 ShaderEffect::ShaderEffect( EventThreadServices& eventThreadServices, Dali::ShaderEffect::GeometryHints hints )
index e43d5fa..c5d3753 100644 (file)
@@ -318,7 +318,8 @@ void GetCameraClippingPlane( RenderTask& renderTask, float& nearClippingPlane, f
 /**
  * Hit test a RenderTask
  */
-bool HitTestRenderTask( LayerList& layers,
+bool HitTestRenderTask( Stage& stage,
+                        LayerList& layers,
                         RenderTask& renderTask,
                         Vector2 screenCoordinates,
                         Results& results,
@@ -365,7 +366,8 @@ bool HitTestRenderTask( LayerList& layers,
         bool stencilOnLayer = false;
         bool stencilHit = false;
         bool layerConsumesHit = false;
-        const Vector2& stageSize = Stage::GetCurrent()->GetSize();
+
+        const Vector2& stageSize = stage.GetSize();
 
         for (int i=layers.GetLayerCount()-1; i>=0 && !(hit.actor); --i)
         {
@@ -428,7 +430,8 @@ bool HitTestRenderTask( LayerList& layers,
  *
  * @return true if we have a hit, false otherwise
  */
-bool HitTestForEachRenderTask( LayerList& layers,
+bool HitTestForEachRenderTask( Stage& stage,
+                               LayerList& layers,
                                RenderTaskList& taskList,
                                const Vector2& screenCoordinates,
                                Results& results,
@@ -458,7 +461,7 @@ bool HitTestForEachRenderTask( LayerList& layers,
       }
     }
 
-    if ( HitTestRenderTask( layers, renderTask, screenCoordinates, results, hitCheck ) )
+    if ( HitTestRenderTask( stage, layers, renderTask, screenCoordinates, results, hitCheck ) )
     {
       // Return true when an actor is hit (or layer in our render-task consumes the hit)
       return true; // don't bother checking off screen tasks
@@ -483,7 +486,7 @@ bool HitTestForEachRenderTask( LayerList& layers,
         continue;
       }
 
-      if ( HitTestRenderTask( layers, renderTask, screenCoordinates, results, hitCheck ) )
+      if ( HitTestRenderTask( stage, layers, renderTask, screenCoordinates, results, hitCheck ) )
       {
         // Return true when an actor is hit (or a layer in our render-task consumes the hit)
         return true;
@@ -504,7 +507,7 @@ bool HitTest( Stage& stage, const Vector2& screenCoordinates, Dali::HitTestAlgor
 
   Results hitTestResults;
   HitTestFunctionWrapper hitTestFunctionWrapper( func );
-  if (  HitTestForEachRenderTask( layerList, taskList, screenCoordinates, hitTestResults, hitTestFunctionWrapper ) )
+  if (  HitTestForEachRenderTask( stage, layerList, taskList, screenCoordinates, hitTestResults, hitTestFunctionWrapper ) )
   {
     results.actor = hitTestResults.actor;
     results.actorCoordinates = hitTestResults.actorCoordinates;
@@ -525,7 +528,7 @@ bool HitTest( Stage& stage, const Vector2& screenCoordinates, Results& results,
     RenderTaskList& overlayTaskList = systemOverlay->GetOverlayRenderTasks();
     LayerList& overlayLayerList = systemOverlay->GetLayerList();
 
-    wasHit = HitTestForEachRenderTask( overlayLayerList, overlayTaskList, screenCoordinates, results, hitTestInterface );
+    wasHit = HitTestForEachRenderTask( stage, overlayLayerList, overlayTaskList, screenCoordinates, results, hitTestInterface );
   }
 
   // Hit-test the regular on-stage actors
@@ -534,7 +537,7 @@ bool HitTest( Stage& stage, const Vector2& screenCoordinates, Results& results,
     RenderTaskList& taskList = stage.GetRenderTaskList();
     LayerList& layerList = stage.GetLayerList();
 
-    wasHit = HitTestForEachRenderTask( layerList, taskList, screenCoordinates, results, hitTestInterface );
+    wasHit = HitTestForEachRenderTask( stage, layerList, taskList, screenCoordinates, results, hitTestInterface );
   }
   return wasHit;
 }
@@ -552,7 +555,7 @@ bool HitTest( Stage& stage, RenderTask& renderTask, const Vector2& screenCoordin
   Results hitTestResults;
 
   HitTestFunctionWrapper hitTestFunctionWrapper( func );
-  if ( HitTestRenderTask( stage.GetLayerList(), renderTask, screenCoordinates, hitTestResults, hitTestFunctionWrapper ) )
+  if ( HitTestRenderTask( stage, stage.GetLayerList(), renderTask, screenCoordinates, hitTestResults, hitTestFunctionWrapper ) )
   {
     results.actor = hitTestResults.actor;
     results.actorCoordinates = hitTestResults.actorCoordinates;
index 97a4328..a4174cb 100644 (file)
@@ -122,10 +122,16 @@ AnimatableMeshPtr AnimatableMesh::New(
 
   Stage* stage = Stage::GetCurrent();
 
-  // Create the event object
-  AnimatableMeshPtr animatableMeshPtr( new AnimatableMesh( *stage, sceneObject, mesh, meshData.GetVertexCount() ) );
-
-  return animatableMeshPtr;
+  if( stage )
+  {
+    // Create the event object
+    AnimatableMeshPtr animatableMeshPtr( new AnimatableMesh( *stage, sceneObject, mesh, meshData.GetVertexCount() ) );
+    return animatableMeshPtr;
+  }
+  else
+  {
+    return NULL;
+  }
 }
 
 AnimatableMesh::~AnimatableMesh()
index 926354f..a1e312f 100644 (file)
@@ -359,32 +359,35 @@ bool RenderTask::TranslateCoordinates( Vector2& screenCoords ) const
   {
     CameraActor* localCamera = GetCameraActor();
     StagePtr stage = Stage::GetCurrent();
-    CameraActor& defaultCamera = stage->GetDefaultCameraActor();
-    if( localCamera )
+    if( stage )
     {
-      Viewport viewport;
-      Vector2 size( stage->GetSize() );
-      viewport.x = viewport.y = 0;
-      viewport.width = size.width;
-      viewport.height = size.height;
-
-      float localX, localY;
-      inside = mMappingConnector.mActor->ScreenToLocal(defaultCamera.GetViewMatrix(), defaultCamera.GetProjectionMatrix(), viewport, localX, localY, screenCoords.x, screenCoords.y);
-      Vector3 actorSize = mMappingConnector.mActor->GetCurrentSize();
-      if( inside && localX >= 0.f && localX <= actorSize.x && localY >= 0.f && localY <= actorSize.y)
+      CameraActor& defaultCamera = stage->GetDefaultCameraActor();
+      if( localCamera )
       {
-        screenCoords.x = localX;
-        screenCoords.y = localY;
+        Viewport viewport;
+        Vector2 size( stage->GetSize() );
+        viewport.x = viewport.y = 0;
+        viewport.width = size.width;
+        viewport.height = size.height;
+
+        float localX, localY;
+        inside = mMappingConnector.mActor->ScreenToLocal(defaultCamera.GetViewMatrix(), defaultCamera.GetProjectionMatrix(), viewport, localX, localY, screenCoords.x, screenCoords.y);
+        Vector3 actorSize = mMappingConnector.mActor->GetCurrentSize();
+        if( inside && localX >= 0.f && localX <= actorSize.x && localY >= 0.f && localY <= actorSize.y)
+        {
+          screenCoords.x = localX;
+          screenCoords.y = localY;
+        }
+        else
+        {
+          inside = false;
+        }
       }
       else
       {
         inside = false;
       }
     }
-    else
-    {
-      inside = false;
-    }
   }
   else if ( mFrameBufferImage && mScreenToFrameBufferFunction )
   {