# UE 4/5 Crashes, Hello World in Third Party Library integration, EXCEPTION\_ACCESS\_VIOLATION

**URL:** <https://forums.unrealengine.com/t/ue-4-5-crashes-hello-world-in-third-party-library-integration-exception-access-violation/581545>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [June 14, 2022, 10:12am UTC](https://forums.unrealengine.com/t/ue-4-5-crashes-hello-world-in-third-party-library-integration-exception-access-violation/581545 "2022-06-14T10:12:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![snook91](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/snook91/32/556060_2.png) [@snook91](https://forums.unrealengine.com/u/snook91)\
**Post date:** [June 14, 2022, 10:12am UTC](https://forums.unrealengine.com/t/ue-4-5-crashes-hello-world-in-third-party-library-integration-exception-access-violation/581545/1 "2022-06-14T10:12:46Z")

</div>

Hello All !

I’m fighting with a EXCEPTION\_ACCESS\_VIOLATION when trying to integrate an Hello World string from a Third Party C++ Library. The strange thing is that the error does not happen every time.

The first time I run the game, everything works (but not every time). The second time I usually have less luck and Unreal Engine crashes.

The first time, usually it works.  
 ![Capture ok](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/4/d/14d200519a41a7d9669e4f9a67133003e20e0741.png)

The second time, usually it crashes.

 ![Capture](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/2/a/92a3aa1ac7aff5b617e27c5acab95afbbea8ae28.png)

Here, you will find the UE log file:

```auto
[2022.06.14-09.42.33:104][773]LogMaterial: Error: MaterialInstance "M_HLOD0_OpenWorld_MainGrid_L1_X-1_Y0_DL0LandscapeStreamingProxy_D7T4VF4LBP34PHV9XOEVM5TIG_1_2_5_0" parameter 'NormalTexture' assigned texture "HLOD0_OpenWorld_MainGrid_L1_X-1_Y0_DL0T_LandscapeStreamingProxy_D7T4VF4LBP34PHV9XOEVM5TIG_1_2_5_0_Normal" requires non-virtual texture

[2022.06.14-09.42.33:104][773]LogStreaming: Display: FlushAsyncLoading: 48 QueuedPackages, 0 AsyncPackages

[2022.06.14-09.42.34:387][773]LogWindows: Error: === Critical error: ===

[2022.06.14-09.42.34:387][773]LogWindows: Error:

[2022.06.14-09.42.34:387][773]LogWindows: Error: Fatal error!

[2022.06.14-09.42.34:387][773]LogWindows: Error:

[2022.06.14-09.42.34:387][773]LogWindows: Error: Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x0000020820800070

[2022.06.14-09.42.34:387][773]LogWindows: Error:

[2022.06.14-09.42.34:387][773]LogWindows: Error: [Callstack] 0x00007ffb02de2f4b UnrealEditor-Core.dll!UnknownFunction []

[2022.06.14-09.42.34:387][773]LogWindows: Error: [Callstack] 0x00007ffb0282a57c UnrealEditor-Core.dll!UnknownFunction []

[2022.06.14-09.42.34:387][773]LogWindows: Error: [Callstack] 0x00007ffac16a1ea1 UnrealEditor-LibBonjour.dll!ABonjourActor::BeginPlay() [C:\Users\moi\Documents\Developpements\UE5\TestExternalLibrary\Plugins\LibBonjour\Source\LibBonjour\Private\BonjourActor.cpp:20]

[2022.06.14-09.42.34:387][773]LogWindows: Error: [Callstack] 0x00007ffb03d14e3f UnrealEditor-Engine.dll!UnknownFunction []

[2022.06.14-09.42.34:387][773]LogWindows: Error: [Callstack] 0x00007ffb05b0ec92 UnrealEditor-Engine.dll!UnknownFunction []

[2022.06.14-09.42.34:387][773]LogWindows: Error: [Callstack] 0x00007ffb04649e21 UnrealEditor-Engine.dll!UnknownFunction []

[2022.06.14-09.42.34:387][773]LogWindows: Error: [Callstack] 0x00007ffb05a38238 UnrealEditor-Engine.dll!UnknownFunction []

[2022.06.14-09.42.34:387][773]LogWindows: Error: [Callstack] 0x00007ffb04604725 UnrealEditor-Engine.dll!UnknownFunction []

[2022.06.14-09.42.34:387][773]LogWindows: Error: [Callstack] 0x00007ffb00b49898 UnrealEditor-UnrealEd.dll!UnknownFunction []

[2022.06.14-09.42.34:387][773]LogWindows: Error: [Callstack] 0x00007ffb00b7ec66 UnrealEditor-UnrealEd.dll!UnknownFunction []

[2022.06.14-09.42.34:387][773]LogWindows: Error: [Callstack] 0x00007ffb00b4a342 UnrealEditor-UnrealEd.dll!UnknownFunction []

[2022.06.14-09.42.34:387][773]LogWindows: Error: [Callstack] 0x00007ffb00b9d42a UnrealEditor-UnrealEd.dll!UnknownFunction []

[2022.06.14-09.42.34:387][773]LogWindows: Error: [Callstack] 0x00007ffb00ba0c37 UnrealEditor-UnrealEd.dll!UnknownFunction []

[2022.06.14-09.42.34:387][773]LogWindows: Error: [Callstack] 0x00007ffb00ba0521 UnrealEditor-UnrealEd.dll!UnknownFunction []

[2022.06.14-09.42.34:387][773]LogWindows: Error: [Callstack] 0x00007ffb0053dcb3 UnrealEditor-UnrealEd.dll!UnknownFunction []

[2022.06.14-09.42.34:387][773]LogWindows: Error: [Callstack] 0x00007ffb00eca666 UnrealEditor-UnrealEd.dll!UnknownFunction []

[2022.06.14-09.42.34:387][773]LogWindows: Error: [Callstack] 0x00007ff6d0a282f6 UnrealEditor.exe!UnknownFunction []

[2022.06.14-09.42.34:387][773]LogWindows: Error: [Callstack] 0x00007ff6d0a40d9c UnrealEditor.exe!UnknownFunction []

[2022.06.14-09.42.34:387][773]LogWindows: Error: [Callstack] 0x00007ff6d0a40e8a UnrealEditor.exe!UnknownFunction []

[2022.06.14-09.42.34:387][773]LogWindows: Error: [Callstack] 0x00007ff6d0a43c4d UnrealEditor.exe!UnknownFunction []

[2022.06.14-09.42.34:387][773]LogWindows: Error: [Callstack] 0x00007ff6d0a55564 UnrealEditor.exe!UnknownFunction []

[2022.06.14-09.42.34:387][773]LogWindows: Error: [Callstack] 0x00007ff6d0a58736 UnrealEditor.exe!UnknownFunction []

[2022.06.14-09.42.34:387][773]LogWindows: Error: [Callstack] 0x00007ffbb8397034 KERNEL32.DLL!UnknownFunction []

[2022.06.14-09.42.34:387][773]LogWindows: Error: [Callstack] 0x00007ffbb9b22651 ntdll.dll!UnknownFunction []

[2022.06.14-09.42.34:387][773]LogWindows: Error:

[2022.06.14-09.42.34:399][773]LogExit: Executing StaticShutdownAfterError

[2022.06.14-09.42.34:400][773]LogWindows: FPlatformMisc::RequestExit(1)

[2022.06.14-09.42.34:400][773]LogWindows: FPlatformMisc::RequestExitWithStatus(1, 3)

[2022.06.14-09.42.34:400][773]LogCore: Engine exit requested (reason: Win RequestExit)

[2022.06.14-09.42.34:406][773]Log file closed, 06/14/22 11:42:34

```

My Project is a blank C++ project.

 ![Capture files](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/6/d/46d2e8c7b300caf5196d08ba3a93d89815b9ab39.png)

I created a blank Third Party Plugin (from the Plugin menu) and added a SayHello() function in the ExampleLibrary files, like this:

```auto
// ExampleLibrary.h
#if defined _WIN32 || defined _WIN64
#define EXAMPLELIBRARY_IMPORT __declspec(dllimport)
#elif defined __linux__
#define EXAMPLELIBRARY_IMPORT __attribute__ ((visibility("default")))
#else
#define EXAMPLELIBRARY_IMPORT
#endif
#include <string>

EXAMPLELIBRARY_IMPORT void ExampleLibraryFunction();
EXAMPLELIBRARY_IMPORT std::string SayHelloFromLib();

```

```auto
// ExampleLibrary.cpp
#if defined _WIN32 || defined _WIN64
    #include <Windows.h>

    #define EXAMPLELIBRARY_EXPORT __declspec(dllexport)
#else
    #include <stdio.h>
#endif

#ifndef EXAMPLELIBRARY_EXPORT
    #define EXAMPLELIBRARY_EXPORT
#endif
#include <string>

EXAMPLELIBRARY_EXPORT void ExampleLibraryFunction()
{
#if defined _WIN32 || defined _WIN64
	MessageBox(NULL, TEXT("ExampleLibrary.dll chargée depuis le Plugin Third Party."), TEXT("Third Party Plugin"), MB_OK);
#else
    printf("ExampleLibrary.dll chargée depuis le Plugin Third Party.");
#endif
}

EXAMPLELIBRARY_EXPORT std::string SayHelloFromLib() {
    return "Bonjour depuis la librairie externe !";
}

```

The SayHello function just returns a std:string.

I created an Actor in my plugin with UE and I edited the BeginPlay function:

```auto
// BonjourActor.cpp
void ABonjourActor::BeginPlay()
{
	Super::BeginPlay();

	FString Message = FString(UTF8_TO_TCHAR(SayHelloFromLib().c_str()));	
	GEngine->AddOnScreenDebugMessage(-1, 10.0, FColor::White, Message);
}

```

Here, you will find my \*.Build.cs files:

```auto
// TestExternalLibrary.Build.cs (the Build.cs of the UE Project)
public class TestExternalLibrary : ModuleRules
{
	public TestExternalLibrary(ReadOnlyTargetRules Target) : base(Target)
	{
		PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
	
		PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "LibBonjour" });

		PrivateDependencyModuleNames.AddRange(new string[] { });
	}
}

```

```auto
// LibBonjour.Build.cs (the Build.cs of the UE Plugin)
PublicDependencyModuleNames.AddRange(
			new string[]
			{
				"Core",
				"LibBonjourLibrary",
				"Projects",
				"Engine",
				"CoreUObject"
				// ... add other public dependencies that you statically link with here ...
			}
			);

```

```auto
// LibBonjourLibrary.Build.cs (the Build.cs of the third party library)
if (Target.Platform == UnrealTargetPlatform.Win64)
		{
			// Add the import library
			PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "x64", "Release", "ExampleLibrary.lib"));

			// Delay-load the DLL, so we can load it from the right place first
			PublicDelayLoadDLLs.Add("ExampleLibrary.dll");

			// Ensure that the DLL is staged along with the executable
			RuntimeDependencies.Add("$(PluginDir)/Binaries/ThirdParty/LibBonjourLibrary/Win64/ExampleLibrary.dll");
        }
        else if (Target.Platform == UnrealTargetPlatform.Mac)
        {
            PublicDelayLoadDLLs.Add(Path.Combine(ModuleDirectory, "Mac", "Release", "libExampleLibrary.dylib"));
            RuntimeDependencies.Add("$(PluginDir)/Source/ThirdParty/LibBonjourLibrary/Mac/Release/libExampleLibrary.dylib");
        }
        else if (Target.Platform == UnrealTargetPlatform.Linux)
		{
			string ExampleSoPath = Path.Combine("$(PluginDir)", "Binaries", "ThirdParty", "LibBonjourLibrary", "Linux", "x86_64-unknown-linux-gnu", "libExampleLibrary.so");
			PublicAdditionalLibraries.Add(ExampleSoPath);
			PublicDelayLoadDLLs.Add(ExampleSoPath);
			RuntimeDependencies.Add(ExampleSoPath);
		}

```

I will be delighted if anyone could help me with this problem. I’m looking for a solution since few days and I really need some support.

Thank you in advance.

Regards.

---

<div class="post-metadata">

**Author:** ![dorusoftware](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dorusoftware](https://forums.unrealengine.com/u/dorusoftware)\
**Post date:** [June 14, 2022, 10:31am UTC](https://forums.unrealengine.com/t/ue-4-5-crashes-hello-world-in-third-party-library-integration-exception-access-violation/581545/2 "2022-06-14T10:31:24Z")

</div>

maybe that library is just faulty, has some errors inside and doesn’t work properly

---

<div class="post-metadata">

**Author:** ![snook91](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/snook91/32/556060_2.png) [@snook91](https://forums.unrealengine.com/u/snook91)\
**Post date:** [June 14, 2022, 10:37am UTC](https://forums.unrealengine.com/t/ue-4-5-crashes-hello-world-in-third-party-library-integration-exception-access-violation/581545/3 "2022-06-14T10:37:17Z")

</div>

Hello dorusoftware,

Thanks for your help.  
The library I use is just a function which returns an std::string. You can see the code of this library above (ExampleLibrary.h/.cpp).

```auto
...
EXAMPLELIBRARY_EXPORT std::string SayHelloFromLib() {
    return "Bonjour depuis la librairie externe !";
}
...

```

I have recompiled this library many times. It comes from the Unreal Engine template provided. I have just added the SayHelloFromLib function.

---

<div class="post-metadata">

**Author:** ![dorusoftware](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dorusoftware](https://forums.unrealengine.com/u/dorusoftware)\
**Post date:** [June 14, 2022, 10:50am UTC](https://forums.unrealengine.com/t/ue-4-5-crashes-hello-world-in-third-party-library-integration-exception-access-violation/581545/4 "2022-06-14T10:50:03Z")

</div>

I don’t know much about programming so not the best user to help you.

One hint I could give that maybe is related is to use the engine implementation of the data types.

so instead of using the c++ data types like string use FString

> **[String Handling](https://docs.unrealengine.com/4.27/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/StringHandling/)**
>
> An overview of the string classes available in UE4 and reference guides for FName, FText, and FString.

---

<div class="post-metadata">

**Author:** ![snook91](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/snook91/32/556060_2.png) [@snook91](https://forums.unrealengine.com/u/snook91)\
**Post date:** [June 14, 2022, 12:07pm UTC](https://forums.unrealengine.com/t/ue-4-5-crashes-hello-world-in-third-party-library-integration-exception-access-violation/581545/5 "2022-06-14T12:07:59Z")

</div>

Thanks for the link. But, the goal is to link with an external library which is written in standard c++ (it’s the feature of the third party library template provided by Epic Games).

---

<div class="post-metadata">

**Author:** ![snook91](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/snook91/32/556060_2.png) [@snook91](https://forums.unrealengine.com/u/snook91)\
**Post date:** [June 20, 2022, 3:09pm UTC](https://forums.unrealengine.com/t/ue-4-5-crashes-hello-world-in-third-party-library-integration-exception-access-violation/581545/6 "2022-06-20T15:09:59Z")

</div>

I’ve found the solution.

It’s due to a non standard stl c++ library implementation ( [Why doesn’t UE utilize STL containers? - Programming & Scripting / C++ - Unreal Engine Forums](https://forums.unrealengine.com/t/why-doesnt-ue-utilize-stl-containers/34551)).  
So, I must not use std::string in my DLL interface (ExampleLibrary.h) and must replace it by:

```auto
EXAMPLELIBRARY_IMPORT char * SayHelloFromLib();

```
