Strange null pointer exception

Hello everyone,
i post this because it’s been 3 hours i’m trying to resolve this strange error.
This causes my editor to crash, so i now launch my editor with visual studio on debug mode.

ULPLAYERCONTROLLER.H:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Widgets")
	TSubclassOf<class UUserWidget> wMainMenu;

	UUserWidget* wMainMenuRef;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Widgets")
	TSubclassOf<class UUserWidget> wPlayMenu;

	UUserWidget* wPlayMenuRef;

so here are my references to my widgets

i initialize them here:

ULPLAYERCONTROLLER.CPP:

void AULPlayerControllerBase::SetupMenuWidgets()
{
	if (IsLocalPlayerController())
	{
		if (wPlayMenu)
		{
			wPlayMenuRef = CreateWidget<UUserWidget>(this, wPlayMenu);
		}
		if (wMainMenu)
		{
			wMainMenuRef = CreateWidget<UUserWidget>(this, wMainMenu);
		}
	
	}
	
}

and then i show them here:

ULPLAYERCONTROLLER.CPP
void AULPlayerControllerBase::BeginPlayMenuState()
{
	if (wPlayMenu)
	{
		if (wPlayMenuRef)
		{
			if (!wPlayMenuRef->IsInViewport())
			{
				wPlayMenuRef->AddToViewport();
			}
				wPlayMenuRef->SetVisibility(ESlateVisibility::Visible);
			
		}
		bShowMouseCursor = true;
	}
	
}
void AULPlayerControllerBase::BeginMainMenuState()
{
	if (wMainMenuRef)
	{
		if (!wMainMenuRef->IsInViewport())
		{
			wMainMenuRef->AddToViewport();
		}

		wMainMenuRef->SetVisibility(ESlateVisibility::Visible);
		bShowMouseCursor = true;
	}
	

}

the thing i dont understand is that the project launch well, the main menu is showed and then when i naviguate to my Play Menu, i have an exception :

Exception thrown at 0x00007FF9641289F6 (UE4Editor-UMG.dll) in UE4Editor.exe: 0xC0000005: Read access violation of location 0xFFFFFFFFFFFFFFFF.

the exception is thrown at this line:

if (!wPlayMenuRef->IsInViewport())

the thing is that i checked this variable and this code should not be accessed if the wplaymenuref is a null pointer.
Thank you for helping me, i’m confused !

You are checking if it is NULL, that is 0x00000000. The variable is instead 0xFFFFFFFF. Thus it passes your test and it does not crash.

It is not a nullpointer exception, it is an access violation error because you try to access RAM outside of what you have. Something before it failed and windows returned 0xFFFFFFFFFF which is the invalid handle error.

HTH

1 Like

So i don’t have enough ram ? is there a way to avoid that ?

No, the problem is that the pointer returned is an error code. It failed to create the object requested, for example a window or open a file, and to tell you that it returns 0xFFFFFFFF. It is not a matter of having enough RAM.

For those who have the same error, i finally figured it out.
I just had to add “UPROPERTY()” to all my UUserWidget references.