title: UE4 C++ - Adding an object with a `TArray` member by value to a `TArray` causes a segfault
body: <p>I have some code that creates a vector of strings in one function, converts that to a <code>TArray&lt;FString&gt;</code>, assigns it to the member variable of an object, and adds that object to a <code>TArray</code>, something like below:</p>
  
  <pre><code>void MyMethod() {
     std::vector&lt;std::string&gt; vec = GetVec();
     TArray&lt;FString&gt; arr = VecStrToTArrFStr(vec);
  
     MyObject obj;
     obj.value = arr;
  
     this-&gt;Objects.Add(obj);
  } 
  </code></pre>
  
  <p>Where the function <code>VecStrToTArrFStr</code> is as follows:</p>
  
  <pre><code>inline TArray&lt;FString&gt; VecStrToTArrFStr(std::vector&lt;std::string&gt; &amp;vec) {
    TArray&lt;FString&gt; arr;
    arr.SetNumUninitialized(vec.size());
  
    for (auto &amp;item : vec) {
      arr.Add(FString(UTF8_TO_TCHAR(item.c_str())));
    }
  
    return arr;
  }
  </code></pre>
  
  <p>This issue occurs on this line:</p>
  
  <pre><code>this-&gt;Objects.Add(obj);
  </code></pre>
  
  <p>For some reason, copying the array throws a segfault. Specifically, it gives this call stack:</p>
  
  <ul>
  <li><code>__memcpy_avx_unaligned (@7fffec5b4ea0..7fffec5b5226:173)</code></li>
  <li><code>FGenericPlatformMemory::Memcpy(void*, void const*, unsigned long) (/UnrealEngine/Engine/Source/Runtime/Core/Public/GenericPlatform/GenericPlatformMemory.h:348)</code></li>
  <li><code>FMemory::Memcpy(void*, void const*, unsigned long) (/UnrealEngine/Engine/Source/Runtime/Core/Public/HAL/UnrealMemory.h:124)</code></li>
  <li><code>TEnableIf&lt;TIsBitwiseConstructible&lt;wchar_t, wchar_t&gt;::Value, void&gt;::Type ConstructItems&lt;wchar_t, wchar_t&gt;(void*, wchar_t const*, int) (/UnrealEngine/Engine/Source/Runtime/Core/Public/Templates/MemoryOps.h:137)</code></li>
  <li><code>void TArray&lt;wchar_t, FDefaultAllocator&gt;::CopyToEmpty&lt;wchar_t&gt;(wchar_t const*, int, int, int) (/UnrealEngine/Engine/Source/Runtime/Core/Public/Containers/Array.h:2508)</code></li>
  <li><code>TArray&lt;wchar_t, FDefaultAllocator&gt;::TArray(TArray&lt;wchar_t, FDefaultAllocator&gt; const&amp;) (/UnrealEngine/Engine/Source/Runtime/Core/Public/Containers/Array.h:338)</code></li>
  <li><code>FString::FString(FString const&amp;) (/UnrealEngine/Engine/Source/Runtime/Core/Public/Containers/UnrealString.h:73)</code></li>
  <li><code>TEnableIf&lt;!(TIsBitwiseConstructible&lt;FString, FString&gt;::Value), void&gt;::Type ConstructItems&lt;FString, FString&gt;(void*, FString const*, int) (/UnrealEngine/Engine/Source/Runtime/Core/Public/Templates/MemoryOps.h:126)</code></li>
  <li><code>void TArray&lt;FString, FDefaultAllocator&gt;::CopyToEmpty&lt;FString&gt;(FString const*, int, int, int) (/UnrealEngine/Engine/Source/Runtime/Core/Public/Containers/Array.h:2508)</code></li>
  <li><code>TArray&lt;FString, FDefaultAllocator&gt;::TArray(TArray&lt;FString, FDefaultAllocator&gt; const&amp;) (/UnrealEngine/Engine/Source/Runtime/Core/Public/Containers/Array.h:338)</code></li>
  <li><code>MyObject::MyObject(MyObject const&amp;) (MyObject.h)</code></li>
  <li><code>int TArray&lt;MyObject, FDefaultAllocator&gt;::Emplace&lt;MyObject const&amp;&gt;(MyObject const&amp;&amp;&amp;) (/UnrealEngine/Engine/Source/Runtime/Core/Public/Containers/Array.h:1843)</code></li>
  <li><code>TArray&lt;MyObject, FDefaultAllocator&gt;::Add(MyObject const&amp;) (/UnrealEngine/Engine/Source/Runtime/Core/Public/Containers/Array.h:1916)</code></li>
  </ul>
  
  <p>Everything runs perfectly fine if I change <code>MyObject.value</code> to be of type <code>std::vector&lt;std::string&gt;</code> and just assign it the <code>vec</code>, but attempting to assign it a <code>TArray&lt;FString&gt;</code> throws a segfault.</p>
  
  <p>What could be causing this? Does it have something to do with how I'm creating my <code>FString</code> objects, or how I'm creating my <code>TArray</code>? Is UE4 doing some garbage collection on the <code>TArray</code> in <code>VecStrToArrFStr</code> or something?</p>