Slate Game Crash

Hi,

I am working through this nice tutorial-series here (http://minalien.com/unreal-engine-4-creating-menus-with-slatec-part-1/) to get familiar with Slate. Currently I am looking into Styles (Part 2 of the tutorial). However for a few days my work has come to a stop because for some reason my game crashes on startup when I try to use my Menu-HUD. It compiles fine though.

This is the error-message I get.


MachineId:5D84F11B4594BE27D2EB1FAE8AA52A47
EpicAccountId:bf70be912eaa4f08b31cadf618d3ce56

Unknown exception - code 00000001 (first/second chance not available)

Assertion failed: IsValid() [File:D:\Program Files\Unreal Engine\4.5\Engine\Source\Runtime\Core\Public\Templates\SharedPointer.h] [Line: 647] 

KERNELBASE + 37901 bytes
UE4Editor_Core + 3174852 bytes
UE4Editor_Core + 1677512 bytes
UE4Editor_Core + 1566866 bytes
UE4Editor_PhunkGame_1661!FMenuStyles::Get() + 49 bytes [d:\users\hammelgammel.pc\documents\unreal projects\phunkgame\source\phunkgame\private\menustyles.cpp:42]
UE4Editor_PhunkGame_1661!SPhunkGameUI::Construct() + 132 bytes [d:\users\hammelgammel.pc\documents\unreal projects\phunkgame\source\phunkgame\private\phunkgameui.cpp:15]
UE4Editor_PhunkGame_1661!TDecl<SPhunkGameUI,RequiredArgs::T0RequiredArgs>::operator<<=() + 138 bytes [d:\program files\unreal engine\4.5\engine\source\runtime\slatecore\public\widgets\declarativesyntaxsupport.h:1321]
UE4Editor_PhunkGame_1661!APhunkGameMainMenuHUD::PostInitializeComponents() + 218 bytes [d:\users\hammelgammel.pc\documents\unreal projects\phunkgame\source\phunkgame\private\phunkgamemainmenuhud.cpp:22]
UE4Editor_Engine + 1807133 bytes
UE4Editor_Engine + 1814466 bytes
UE4Editor_Engine + 5087211 bytes
UE4Editor_Engine + 6270047 bytes
UE4Editor_Engine + 1086054 bytes
UE4Editor_CoreUObject + 549780 bytes
UE4Editor_CoreUObject + 1438322 bytes
UE4Editor_Engine + 1818193 bytes
UE4Editor_Engine + 16885913 bytes
UE4Editor_Engine + 3883871 bytes
UE4Editor_Engine + 3828248 bytes
UE4Editor_Engine + 5088808 bytes
UE4Editor_Engine + 5610996 bytes
UE4Editor_Engine + 3885659 bytes
UE4Editor_UnrealEd + 4144983 bytes
UE4Editor_UnrealEd + 4429648 bytes
UE4Editor_UnrealEd + 4526262 bytes
UE4Editor_UnrealEd + 1893329 bytes
UE4Editor_UnrealEd + 6486374 bytes
UE4Editor!FEngineLoop::Tick() + 3524 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.5\engine\source\runtime\launch\private\launchengineloop.cpp:2129]
UE4Editor!GuardedMain() + 479 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.5\engine\source\runtime\launch\private\launch.cpp:133]
UE4Editor!GuardedMainWrapper() + 26 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.5\engine\source\runtime\launch\private\windows\launchwindows.cpp:125]
UE4Editor!WinMain() + 249 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.5\engine\source\runtime\launch\private\windows\launchwindows.cpp:201]
UE4Editor!__tmainCRTStartup() + 329 bytes [f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c:618]


From what I am reading there, I assume there is a problem with a pointer. And since commenting this line

“MenuStyle = &FMenuStyles::Get().GetWidgetStyle(“Global”);”

stops the crashes (I can’t use my Style though), and it generally always crashes whenever I call the get()-function of the MenuStyles-class it must be something with the “MenuStylesInstance”-pointer. So the problem probably lies within the “MenuStyles”-class. But I can’t for the life of me figure it out. I have the same files in the same folders as the Tutorial, so it is probably not something related to the actual files. I downloaded the finished files from the tutorial-site and it worked fine on 4.5 so it definitly is me doing something wrong here.

Those should be the important files. I guess the problem is in MenuStlyes.

MenuStyles.h


#pragma once

class FMenuStyles
{
public:

	static void Initialize();

	static void Shutdown();

	static const class ISlateStyle& Get();

	static FName GetStyleSetName();

private:

	static TSharedRef<class FSlateStyleSet> Create();

	static TSharedPtr<class FSlateStyleSet> MenuStyleInstance;
};

MenuStyles.cpp


#include "PhunkGame.h"

#include "MenuStyles.h"
#include "Slate.h"
#include "SlateGameResources.h"

TSharedPtr<FSlateStyleSet> FMenuStyles::MenuStyleInstance;

void FMenuStyles::Initialize()
{
	if (!MenuStyleInstance.IsValid())
	{
		MenuStyleInstance = Create();
		FSlateStyleRegistry::RegisterSlateStyle(*MenuStyleInstance);
	}
}

void FMenuStyles::Shutdown()
{
	FSlateStyleRegistry::UnRegisterSlateStyle(*MenuStyleInstance);
	ensure(MenuStyleInstance.IsUnique());
	MenuStyleInstance.Reset();
}

FName FMenuStyles::GetStyleSetName()
{
	static FName StyleSetName(TEXT("MenuStyles"));
	return StyleSetName;
}

TSharedRef<FSlateStyleSet> FMenuStyles::Create()
{
	TSharedRef<FSlateStyleSet> StyleRef = FSlateGameResources::New(FMenuStyles::GetStyleSetName(), "/Game/UI/Styles", "/Game/UI/Styles");

	return StyleRef;
}


const ISlateStyle& FMenuStyles::Get()
{
	return *MenuStyleInstance;
}

PhunkGameUI.h


#pragma once

#include "Slate.h"

class SPhunkGameUI : public SCompoundWidget
{
	SLATE_BEGIN_ARGS(SPhunkGameUI)
		: _MenuHUD()
	{
	}

	SLATE_ARGUMENT(TWeakObjectPtr<class APhunkGameMainMenuHUD>, MenuHUD);

	SLATE_END_ARGS()

public:

	void Construct(const FArguments& args);

private:

	FReply PlayGameClicked();

	FReply QuitGameClicked();

	TWeakObjectPtr<class APhunkGameMainMenuHUD> MenuHUD;

	const struct FGlobalStyle* MenuStyle;
};

PhunkGameUI.cpp


#include "PhunkGame.h"

#include "PhunkGameMainMenuHUD.h"
#include "PhunkGameUI.h"
#include "GlobalMenuStyle.h"
#include "MenuStyles.h"

void SPhunkGameUI::Construct(const FArguments& args)
{
	MenuHUD = args._MenuHUD;

	MenuStyle = &FMenuStyles::Get().GetWidgetStyle<FGlobalStyle>("Global");


	ChildSlot
		
			SNew(SOverlay)
			+ SOverlay::Slot()
			.HAlign(HAlign_Center)
			.VAlign(VAlign_Top)
			
				SNew(STextBlock)
				//.TextStyle(&MenuStyle->MenuTitleStyle)
				.Text(FText::FromString("Hauptmenue"))
			]
			+ SOverlay::Slot()
				.HAlign(HAlign_Right)
				.VAlign(VAlign_Bottom)
				
					SNew(SVerticalBox)
					+ SVerticalBox::Slot()
					
						SNew(SButton)
						//.ButtonStyle(&MenuStyle->MenuButtonStyle)
						//.TextStyle(&MenuStyle->MenuButtonTextStyle)
						.Text(FText::FromString("Spiel starten"))
						.OnClicked(this, &SPhunkGameUI::PlayGameClicked)
					]
					+ SVerticalBox::Slot()
						
							SNew(SButton)
							//.ButtonStyle(&MenuStyle->MenuButtonStyle)
							//.TextStyle(&MenuStyle->MenuButtonTextStyle)
							.Text(FText::FromString("Spiel beenden"))
							.OnClicked(this, &SPhunkGameUI::QuitGameClicked)
						]
				]
		];
}

FReply SPhunkGameUI::PlayGameClicked()
{
	MenuHUD->PlayGameClicked();
	return FReply::Handled();
}

FReply SPhunkGameUI::QuitGameClicked()
{
	MenuHUD->QuitGameClicked();
	return FReply::Handled();
}

I hope I didn’t post too much. But I tried to provide every info necessary. It is probably something very simple I am missing, but I can’t find it. I hope one of you does. Thank you very much in advance! :slight_smile:

I have a similar problem using blueprints widgets. Every time I try to edit a widget the engine crash.
New projects don´t have this problem. But after the first widget run it starts.

Unknown exception - code 00000001 (first/second chance not available)
Assertion failed: IsValid() [File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.5\Engine\Source\Runtime\Core\Public\Templates\SharedPointer.h] [Line: 658]

Would be interesting to know if the problems are related in some way. But I assume in my case, I just did something wrong in the code. I just don’t get it. It seems that I do everything exactly the same as the project that works fine.

Im not sure if you’re familiar with singleton design because FMenuStyles is suppose to be one.
Read about it on wiki and ask yourself a question: How many times should I initialize singleton and where is it in my code? :wink:

I still can’t get it to work. I even copied the files of the working project in a new project, and just changed the includes of my Project-header. I don’t understand why this is not working :frowning: