Browse Source

Update return value of SharedPtr<T>::Detach.

Eugene Kozlov 9 years ago
parent
commit
6a469e6af8
2 changed files with 5 additions and 9 deletions
  1. 2 8
      Source/Urho3D/AngelScript/GraphicsAPI.cpp
  2. 3 1
      Source/Urho3D/Container/Ptr.h

+ 2 - 8
Source/Urho3D/AngelScript/GraphicsAPI.cpp

@@ -181,18 +181,12 @@ static Viewport* ConstructViewportSceneCameraRect(Scene* scene, Camera* camera,
 
 static Image* Texture2DGetImage(Texture2D* tex2d)
 {
-    SharedPtr<Image> sharedImage = tex2d->GetImage();
-    Image* image = sharedImage;
-    sharedImage.Detach();
-    return image;
+    return tex2d->GetImage().Detach();
 }
 
 static Image* TextureCubeGetImage(CubeMapFace face, TextureCube* texCube)
 {
-    SharedPtr<Image> sharedImage = texCube->GetImage(face);
-    Image* image = sharedImage;
-    sharedImage.Detach();
-    return image;
+    return texCube->GetImage(face).Detach();
 }
 
 static void ConstructRenderTargetInfo(RenderTargetInfo* ptr)

+ 3 - 1
Source/Urho3D/Container/Ptr.h

@@ -151,8 +151,9 @@ public:
     void Reset() { ReleaseRef(); }
 
     /// Detach without destroying the object even if the refcount goes zero. To be used for scripting language interoperation.
-    void Detach()
+    T* Detach()
     {
+        T* ptr = ptr_;
         if (ptr_)
         {
             RefCount* refCount = RefCountPtr();
@@ -160,6 +161,7 @@ public:
             Reset(); // 1 ref
             --refCount->refs_; // 0 refs
         }
+        return ptr;
     }
 
     /// Perform a static cast from a shared pointer of another type.