Call AddToViewport get Crash

I have multi triggers, All AddDynamic to My TriggerBeginOverlap & TriggerEndOverlap, like this:

		box->OnComponentBeginOverlap.AddDynamic(this, &ACubeActor::TriggerBeginOverlap);
		box->OnComponentEndOverlap.AddDynamic(this, &ACubeActor::TriggerEndOverlap);

And in the trigger I will open my widget:

void ACubeActor::TriggerBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) {
	ADarkSoulPawn* Player = Cast<ADarkSoulPawn>(OtherActor);
	if (Player) {
		UCustomMovementComponent* Comp = Cast<UCustomMovementComponent>(Player->GetMovementComponent());
		if (Comp) {
			......
		
			if (MySystem) {
				MySystem->bCubeSelectWidgetOnScreen = false;
				MySystem->HandleCubeSelectWidget();
			}
		}
	}
}

use this to open my widget…

void ASceneCubeActor::HandleCubeSelectWidget() {
	if (CubeSelectWidgetRef)
	{
		if (bCubeSelectWidgetOnScreen)
		{
			//Mark the inventory as closed
			bCubeSelectWidgetOnScreen = false;

			//Remove it from the viewport
			CubeSelectWidgetRef->RemoveFromViewport();

			// Hide the cursor of our game
			MyController->bShowMouseCursor = false;

			// Tell the game that we want to register inputs for our game
			FInputModeGameOnly InputMode;
			MyController->SetInputMode(InputMode);

		}
		else
		{
			//Mark the inventory as open
			bCubeSelectWidgetOnScreen = true;

			//Re-populate the ItemsArray
			//Show the inventory
			// MySystem->CubeSelectWidgetRef->Load();
			CubeSelectWidgetRef->AddToViewport();

			// Hide the cursor of our game
			MyController->bShowMouseCursor = true;

			// Tell the game that we want to register inputs for our game
			FInputModeGameAndUI InputMode;
			// FInputModeGameAndUI InputMode;
			MyController->SetInputMode(InputMode);

		}
	}
}

And I change trigger and open my widget and close, after many times(may be 20 or 30), I will get crashed when call AddToViewport

this is crash log:
[2017.09.10-11.42.16:815][424]LogCrashTracker:

[2017.09.10-11.42.16:815][424]LogCrashTracker: 


[2017.09.10-11.42.16:815][424]LogWindows:Error: === Critical error: ===
[2017.09.10-11.42.16:815][424]LogWindows:Error: 
[2017.09.10-11.42.16:815][424]LogWindows:Error: Fatal error!
[2017.09.10-11.42.16:815][424]LogWindows:Error: 
[2017.09.10-11.42.16:815][424]LogWindows:Error: Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0xffffffff
[2017.09.10-11.42.16:815][424]LogWindows:Error: 
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-UMG.dll!0x00000000B31C3F98
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-DarkSoul-9944.dll!ASceneCubeActor::HandleCubeSelectWidget() [f:\...\scenecubeactor.cpp:365]
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-DarkSoul-9944.dll!ACubeActor::TriggerBeginOverlap() [f:\ureal_project\darksoul\source\darksoul\scene\cubeactor.cpp:131]
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-DarkSoul-9944.dll!ACubeActor::execTriggerBeginOverlap() [f:\...\cubeactor.h:12]
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-CoreUObject.dll!0x00000000D2828734
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-CoreUObject.dll!0x00000000D29FD366
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-Engine.dll!0x00000000B7523F27
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-Engine.dll!0x00000000B74A52A9
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-Engine.dll!0x00000000B79DB798
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-Engine.dll!0x00000000B79C8C06
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-Engine.dll!0x00000000B7A0883C
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-Engine.dll!0x00000000B79EAACA
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-Engine.dll!0x00000000B7991716
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-Engine.dll!0x00000000B79A0344
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-Engine.dll!0x00000000B7BDFB9F
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-DarkSoul-9944.dll!UCustomMovementComponent::TickComponent() [f:\...\custommovementcomponent.cpp:72]
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-Engine.dll!0x00000000B78D4884
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-Engine.dll!0x00000000B7908695
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-Engine.dll!0x00000000B84D379B
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-Engine.dll!0x00000000B84DA17B
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-Core.dll!0x00000000BA824D8C
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-Core.dll!0x00000000BA8251AD
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-Core.dll!0x00000000BA83FA66
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-Engine.dll!0x00000000B84F6662
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-Engine.dll!0x00000000B84FBBC2
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-Engine.dll!0x00000000B7E1E504
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-Engine.dll!0x00000000B7E265CF
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-UnrealEd.dll!0x00000000B6033973
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor-UnrealEd.dll!0x00000000B6858D86
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor.exe!0x0000000038FAE2B2
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor.exe!0x0000000038F9F0B0
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor.exe!0x0000000038F9F12A
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor.exe!0x0000000038FB0CF9
[2017.09.10-11.42.16:815][424]LogWindows:Error: UE4Editor.exe!0x0000000038FB25F7
[2017.09.10-11.42.16:815][424]LogWindows:Error: KERNEL32.DLL!0x00000000FF372774
[2017.09.10-11.42.16:815][424]LogWindows:Error: ntdll.dll!0x00000000FFF50D51
[2017.09.10-11.42.16:815][424]LogWindows:Error: ntdll.dll!0x00000000FFF50D51
[2017.09.10-11.42.16:815][424]LogWindows:Error: 
[2017.09.10-11.42.16:827][424]LogExit: Executing StaticShutdownAfterError
[2017.09.10-11.42.16:833][424]LogWindows: FPlatformMisc::RequestExit(1)
[2017.09.10-11.42.16:833][424]Log file closed, 09/10/17 19:42:16

I can’t solve this…Want some help…

Solve it, Need to add UPROERTY() to uuserwidget reference

1 Like

I owe you a beer :slight_smile: Thanks