Crash with Slate Widget

Recently got into learning how to use Slate Widget.

I was trying to initialize the Slate Widget when pressing “B” but upon pressing the editor crashes on the line:

BuilderInventoryWidget = SNew(SBuilderInventoryWidget).OwningHUD(this);

Here’s the code in the CPP file for when I call the function.

void ABuilderInventoryHUD::SetBuilderInventoryHUD()
{
	if(GEngine && GEngine->GameViewport)
	{
		BuilderInventoryWidget = SNew(SBuilderInventoryWidget).OwningHUD(this);
		GEngine->GameViewport->AddViewportWidgetContent(SAssignNew(BuilderInventoryWidgetContainer, SWeakWidget).PossiblyNullContent(BuilderInventoryWidget.ToSharedRef()));
	}
}

Here’s the Slate Widget I want to set:

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "SlateBasics.h"
#include "SlateExtras.h"

/**
 * 
 */
class SBuilderInventoryWidget : public SCompoundWidget
{
public:
	SLATE_BEGIN_ARGS(SBuilderInventoryWidget) {}
	SLATE_ARGUMENT(TWeakObjectPtr<class ABuilderInventoryHUD>, OwningHUD)
	SLATE_END_ARGS()

	void Construct(const FArguments& InArgs);
	
	TWeakObjectPtr<class ABuilderInventoryHUD> OwningHUD;

	virtual bool SupportsKeyboardFocus() const override { return true; };

	
};

I also added the private dependency modules “Slate” and “SlateCore”

My guess is that I’m initializing SBuilderInventoryWidget wrong somehow, but I’m not too sure how to fix this. Thanks in advance :))

Do not use smart pointer on UObject, it already has its own lifecycle manager.
If it still crashing, please post the crash message.

Hey! sorry for the late reply. For the smart pointers, I just deleted the TWeakPtr variable and all references to it. Hopefully I did that part correctly.

Here’s the widget h file:

class SBuilderInventoryWidget : public SCompoundWidget
{
public:
	SLATE_BEGIN_ARGS(SBuilderInventoryWidget) {}
	SLATE_END_ARGS()

	void Construct(const FArguments& InArgs);

	virtual bool SupportsKeyboardFocus() const override { return true; };

	
};

Here’s the function creating the widget.

void ABuilderInventoryHUD::SetBuilderInventoryHUD()
{
	if(GEngine && GEngine->GameViewport)
	{
		BuilderInventoryWidget = SNew(SBuilderInventoryWidget);
		GEngine->GameViewport->AddViewportWidgetContent(SAssignNew(BuilderInventoryWidgetContainer, SWeakWidget).PossiblyNullContent(BuilderInventoryWidget.ToSharedRef()));
	}
}

Unfortunately it still crashed.

I’m not too sure how to post the crash report properly so I just copy and pasted.
Here it is:

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION writing address 0x00000000000004f0

UnrealEditor_MyProject2!ABuilderInventoryHUD::SetBuilderInventoryHUD() [D:\Projects\Unreal Projects\MyProject2\Source\MyProject2\BuilderInventoryHUD.cpp:18]
UnrealEditor_MyProject2!ACPP_PlayerBase::BuildMode() [D:\Projects\Unreal Projects\MyProject2\Source\MyProject2\CPP_PlayerBase.cpp:950]
UnrealEditor_MyProject2!TBaseUObjectMethodDelegateInstance<0,ACPP_PlayerBase,void __cdecl(void),FDefaultDelegateUserPolicy>::Execute() [D:\InstalledPrograms\UE_5.2\Engine\Source\Runtime\Core\Public\Delegates\DelegateInstancesImpl.h:535]
UnrealEditor_EnhancedInput!UEnhancedPlayerInput::ProcessInputStack() [D:\build\++UE5\Sync\Engine\Plugins\EnhancedInput\Source\EnhancedInput\Private\EnhancedPlayerInput.cpp:490]
UnrealEditor_Engine!APlayerController::ProcessPlayerInput() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\PlayerController.cpp:2704]
UnrealEditor_Engine!APlayerController::TickPlayerInput() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\PlayerController.cpp:4985]
UnrealEditor_Engine!APlayerController::PlayerTick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\PlayerController.cpp:2308]
UnrealEditor_Engine!APlayerController::TickActor() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\PlayerController.cpp:5137]
UnrealEditor_Engine!FActorTickFunction::ExecuteTick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Actor.cpp:212]
UnrealEditor_Engine!FTickFunctionTask::DoTask() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\TickTaskManager.cpp:275]
UnrealEditor_Engine!TGraphTask<FTickFunctionTask>::ExecuteTask() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Async\TaskGraphInterfaces.h:1310]
UnrealEditor_Core!FNamedTaskThread::ProcessTasksNamedThread() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:758]
UnrealEditor_Core!FNamedTaskThread::ProcessTasksUntilQuit() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:649]
UnrealEditor_Core!FTaskGraphCompatibilityImplementation::WaitUntilTasksComplete() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:2123]
UnrealEditor_Engine!FTickTaskSequencer::ReleaseTickGroup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\TickTaskManager.cpp:556]
UnrealEditor_Engine!FTickTaskManager::RunTickGroup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\TickTaskManager.cpp:1583]
UnrealEditor_Engine!UWorld::RunTickGroup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\LevelTick.cpp:770]
UnrealEditor_Engine!UWorld::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\LevelTick.cpp:1512]
UnrealEditor_UnrealEd!UEditorEngine::Tick() [D:\build\++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\EditorEngine.cpp:1905]
UnrealEditor_UnrealEd!UUnrealEdEngine::Tick() [D:\build\++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\UnrealEdEngine.cpp:519]
UnrealEditor!FEngineLoop::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\LaunchEngineLoop.cpp:5812]
UnrealEditor!GuardedMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Launch.cpp:188]
UnrealEditor!GuardedMainWrapper() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:107]
UnrealEditor!LaunchWindowsStartup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:244]
UnrealEditor!WinMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:284]
UnrealEditor!__scrt_common_main_seh() [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288]
kernel32
ntdll

looks like u are calling a function from a null pointer
it could be at here BuilderInventoryHUD.cpp:18

Yeah I figured that it was a null pointer. Couldn’t figure it out though so at the moment I’m just going to go back to UMG and try figuring out Slate later. Thanks for the help though :))

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.