UE4 和 Azure 存储 sdk

UE4 and Azure storage sdk

我正在尝试使用带有 Unreal Engine 4 的 Azure 存储 sdk C++ 库将图像上传到 Azure 云。库是用 vcpkg 构建的,dll 是动态链接的。这是我使用的代码的简化示例。

THIRD_PARTY_INCLUDES_START
#pragma warning(disable:4668) 
#pragma warning(disable:4005)   // 'TEXT': macro redefinition
#include <was/storage_account.h>
#include <was/blob.h>
#include <cpprest/filestream.h>  
#include <cpprest/containerstream.h> 
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<uint8_t>::open_istream(U("image.jpg")).get();
        blockBlob.upload_from_stream(input_stream);
        input_stream.close().wait();
    }
    catch (const std::exception& e)
    {
        std::wcout << U("Error: ") << e.what() << std::endl;
    }
}

Build.cs内容

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");
        }
    }
}

问题是它成功上传图像并在 return 之后从这个函数(在本例中为调用堆栈中的 StartPlay() 或 Upload())立即崩溃,调用堆栈为:

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<wchar_t>::deallocate(wchar_t * const) Line 992   C++
UE4Editor-MsgQueuePlugin.dll!std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >::_Tidy_deallocate() Line 3992    C++
[Inline Frame] UE4Editor-MsgQueuePlugin.dll!std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >::{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<unsigned char,FDefaultAllocator> file, const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & path, const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & fileName) Line 37  C++

带有编辑器调试符号的调用堆栈:

[Inline Frame] UE4Editor-Core.dll!__TBB_machine_cmpswp1(volatile void *) Line 69    C++
[Inline Frame] UE4Editor-Core.dll!__TBB_TryLockByte(unsigned char &) Line 917   C++
UE4Editor-Core.dll!__TBB_LockByte(unsigned char & flag) Line 924    C++
[Inline Frame] UE4Editor-Core.dll!MallocMutex::scoped_lock::{ctor}(MallocMutex &) 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<unsigned char,FDefaultAllocator> file, const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & path, const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & fileName) Line 37  C++

看起来它在从某些结构中删除 uri 时崩溃了。可能问题出在虚幻的内存管理上。我尝试使用 ansi 分配器,但没有用。任何想法如何使其正常工作? 谢谢

最后用this example的UE4插件解决了。这不是我想要的解决方案,但至少它有效。有静态链接库和硬编码的编译器版本,将来可能会带来问题。