Resolve C# retrieving string output lifecycle 36/283336/1
authorEunki, Hong <eunkiki.hong@samsung.com>
Mon, 24 Oct 2022 13:08:23 +0000 (22:08 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Mon, 24 Oct 2022 13:09:40 +0000 (22:09 +0900)
Change-Id: I95a1b865efa3c2c9171d6c5d810d953e2cd41b9a
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
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);