title: UE4 and Azure storage sdk
body: <p>I am trying to use Azure storage sdk C++ library with Unreal Engine 4 to upload images to the Azure cloud. Library is built with vcpkg and dlls are linked dynamically. Here is a simplified example of the code I use.</p>
  
  <pre><code>THIRD_PARTY_INCLUDES_START
  #pragma warning(disable:4668) 
  #pragma warning(disable:4005)   // 'TEXT': macro redefinition
  #include &lt;was/storage_account.h&gt;
  #include &lt;was/blob.h&gt;
  #include &lt;cpprest/filestream.h&gt;  
  #include &lt;cpprest/containerstream.h&gt; 
  THIRD_PARTY_INCLUDES_END
  
  const utility::string_t storage_connection_string(U("DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=MyAccountKey;EndpointSuffix=core.windows.net"));
  
  void AAwsTest2GameModeBase::StartPlay() {
      try
      {
          // Retrieve storage account from connection string.
          azure::storage::cloud_storage_account storage_account = azure::storage::cloud_storage_account::parse(storage_connection_string);
  
          // Create the blob client.
          azure::storage::cloud_blob_client blob_client = storage_account.create_cloud_blob_client();
  
          // Retrieve a reference to a container.
          azure::storage::cloud_blob_container container = blob_client.get_container_reference(U("image-container"));
  
          azure::storage::cloud_block_blob blockBlob = container.get_block_blob_reference(U("28bbcdb0b3e5417b207572e292ae98412cd9d931eae6266f7c4fd788ad8544a20.jpg"));
  
          concurrency::streams::istream input_stream = concurrency::streams::file_stream&lt;uint8_t&gt;::open_istream(U("image.jpg")).get();
          blockBlob.upload_from_stream(input_stream);
          input_stream.close().wait();
      }
      catch (const std::exception&amp; e)
      {
          std::wcout &lt;&lt; U("Error: ") &lt;&lt; e.what() &lt;&lt; std::endl;
      }
  }
  </code></pre>
  
  <p>Build.cs content</p>
  
  <pre><code>public class Program : ModuleRules
  {
      public Program(ReadOnlyTargetRules Target) : base(Target)
      {
          PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
  
          PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
  
          //I tried to use ansi allocator but it did not help
          //PublicDefinitions.Add("FORCE_ANSI_ALLOCATOR");
  
          PublicIncludePaths.Add(Path.Combine(DependencyFolderWin, "include"));
          PublicAdditionalLibraries.Add(Path.Combine(DependencyFolderWin, "lib", "wastorage.lib"));
          PublicAdditionalLibraries.Add(Path.Combine(DependencyFolderWin, "lib", "cpprest_2_10.lib"));
          PublicAdditionalLibraries.Add(Path.Combine(DependencyFolderWin, "lib", "brotlicommon.lib"));
          PublicAdditionalLibraries.Add(Path.Combine(DependencyFolderWin, "lib", "brotlidec.lib"));
          PublicAdditionalLibraries.Add(Path.Combine(DependencyFolderWin, "lib", "brotlienc.lib"));
          PublicAdditionalLibraries.Add(Path.Combine(DependencyFolderWin, "lib", "zlib.lib"));
  
      }
  
      private string DependencyFolderWin
      {
          get
          {
              string moduleDir = Path.GetFullPath(ModuleDirectory);
              return Path.Combine(moduleDir, "./../../deps");
          }
      }
  }
  </code></pre>
  
  <p>The problem is that it successfully uploads image and crashes right after return from this function (in this case StartPlay() or Upload() as in the callstack) with this callstack:</p>
  
  <pre><code>UE4Editor-Core.dll!00007ff9e620ff1b()   Unknown
  UE4Editor-Core.dll!00007ff9e62109e3()   Unknown
  UE4Editor-Core.dll!00007ff9e6211592()   Unknown
  UE4Editor-Core.dll!00007ff9e5e95277()   Unknown
  [Inline Frame] UE4Editor-MsgQueuePlugin.dll!operator delete(void *) Line 31 C++
  [Inline Frame] UE4Editor-MsgQueuePlugin.dll!std::_Deallocate(void * _Ptr, unsigned __int64 _Bytes) Line 207 C++
  [Inline Frame] UE4Editor-MsgQueuePlugin.dll!std::allocator&lt;wchar_t&gt;::deallocate(wchar_t * const) Line 992   C++
  UE4Editor-MsgQueuePlugin.dll!std::basic_string&lt;wchar_t,std::char_traits&lt;wchar_t&gt;,std::allocator&lt;wchar_t&gt; &gt;::_Tidy_deallocate() Line 3992    C++
  [Inline Frame] UE4Editor-MsgQueuePlugin.dll!std::basic_string&lt;wchar_t,std::char_traits&lt;wchar_t&gt;,std::allocator&lt;wchar_t&gt; &gt;::{dtor}() Line 2460   C++
  UE4Editor-MsgQueuePlugin.dll!web::uri::~uri()   C++
  UE4Editor-MsgQueuePlugin.dll!azure::storage::cloud_blob::~cloud_blob()  C++
  UE4Editor-MsgQueuePlugin.dll!AzureUploader::Upload(TArray&lt;unsigned char,FDefaultAllocator&gt; file, const std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &amp; path, const std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &amp; fileName) Line 37  C++
  </code></pre>
  
  <p>Callstack with Editor debug symbols:</p>
  
  <pre><code>[Inline Frame] UE4Editor-Core.dll!__TBB_machine_cmpswp1(volatile void *) Line 69    C++
  [Inline Frame] UE4Editor-Core.dll!__TBB_TryLockByte(unsigned char &amp;) Line 917   C++
  UE4Editor-Core.dll!__TBB_LockByte(unsigned char &amp; flag) Line 924    C++
  [Inline Frame] UE4Editor-Core.dll!MallocMutex::scoped_lock::{ctor}(MallocMutex &amp;) Line 66   C++
  UE4Editor-Core.dll!rml::internal::Block::freePublicObject(rml::internal::FreeObject * objectToFree) Line 1382   C++
  [Inline Frame] UE4Editor-Core.dll!rml::internal::internalPoolFree(rml::internal::MemoryPool * memPool, void *) Line 2571    C++
  UE4Editor-Core.dll!rml::internal::internalFree(void * object) Line 2595 C++
  UE4Editor-Core.dll!FMemory::Free(void * Original) Line 76   C++
  [External Code] 
  UE4Editor-MsgQueuePlugin.dll!AzureUploader::Upload(TArray&lt;unsigned char,FDefaultAllocator&gt; file, const std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &amp; path, const std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &amp; fileName) Line 37  C++
  </code></pre>
  
  <p>Looks like it crashes while deleting uri from some structure. Probably, the problem is with unreal memory management. I tried to use ansi allocator but it did not help. Any ideas how to make it work properly? 
  Thank you</p>