Browse Source

Crash due to call of StaticSprite2D::SetSprite if param is null.

If mouse left button hit a sprite tile in 36_Urho2DTileMap sample, it
make a crash.
Y-way 9 years ago
parent
commit
be8cbb43ba
1 changed files with 8 additions and 2 deletions
  1. 8 2
      Source/Urho3D/Urho2D/StaticSprite2D.cpp

+ 8 - 2
Source/Urho3D/Urho2D/StaticSprite2D.cpp

@@ -32,6 +32,7 @@
 #include "../Urho2D/StaticSprite2D.h"
 
 #include "../DebugNew.h"
+#include "../IO/Log.h"
 
 namespace Urho3D
 {
@@ -84,6 +85,11 @@ void StaticSprite2D::RegisterObject(Context* context)
 
 void StaticSprite2D::SetSprite(Sprite2D* sprite)
 {
+	if (!sprite)
+	{
+		URHO3D_LOGERROR("Sprite must not be null!");
+		return;
+	}
     if (sprite == sprite_)
         return;
 
@@ -352,12 +358,12 @@ void StaticSprite2D::UpdateDrawRect()
     {
         if (useHotSpot_)
         {
-            if (!sprite_->GetDrawRectangle(drawRect_, hotSpot_, flipX_, flipY_))
+            if (sprite_ && !sprite_->GetDrawRectangle(drawRect_, hotSpot_, flipX_, flipY_))
                 return;
         }
         else
         {
-            if (!sprite_->GetDrawRectangle(drawRect_, flipX_, flipY_))
+            if (sprite_ && !sprite_->GetDrawRectangle(drawRect_, flipX_, flipY_))
                 return;
         }
     }