Resolve C# retrieving string output lifecycle
[platform/core/uifw/dali-csharp-binder.git] / dali-csharp-binder / src / internal-visual-property-get-set-wrap.cpp
index 710d934..c35e7a2 100755 (executable)
@@ -186,6 +186,12 @@ extern "C"
 
     try
     {
+      // Copy inputed initialized string.
+      // Note : C# side inputed string reference count become reduced.
+      // So, If we want to keep life when we fail to get result,
+      // We should re-convert by SWIG_csharp_string_callback.
+      std::string temp = (*valString == nullptr) ? "" : *valString;
+
       Dali::Toolkit::Internal::Control& internalControl = Dali::Toolkit::Internal::GetImplementation(*pControl);
       Dali::Toolkit::Visual::Base       visualBase      = Dali::Toolkit::DevelControl::GetVisual(internalControl, visualIndex);
       if(visualBase)
@@ -196,13 +202,13 @@ extern "C"
         if(retValuePtr)
         {
           //typemap in
-          std::string temp = retValuePtr->Get<std::string>();
-
-          //Typemap argout in c++ file.
-          //This will convert c++ string to c# string
-          *valString = SWIG_csharp_string_callback(temp.c_str());
+          temp = retValuePtr->Get<std::string>();
         }
       }
+
+      //Typemap argout in c++ file.
+      //This will convert c++ string to c# string
+      *valString = SWIG_csharp_string_callback(temp.c_str());
     }
     CALL_CATCH_EXCEPTION((int)InternalPropertyReturnType::ERROR_UNKNOWN);