Download

Editor mode plugin crash

Hello UE4 community. I’ve been trying to fix a problem with editor crash. It occurs when I try to click on my custom plugin in editor modes. The delegates in SEditableTextBox seem to be the problem because when I comment them out everything works but no idea why. Here’s the code:

GridToolsEdModeToolkit.h


    

     FText GetRadius() const;
     void SetRadius(const FText& InText);
     static int32 Radius;
     

GridToolsEdModeToolkit.cpp




int32 FGridToolsEdModeToolkit::Radius = 0;

	
FGridToolsEdModeToolkit::FGridToolsEdModeToolkit()
{
        struct Locals
	{
		static bool IsWidgetEnabled()
		{
			return GEditor->GetSelectedActors()->Num() != 0;
		}
	};


                 SAssignNew(ToolkitWidget, SBorder)
		.VAlign(VAlign_Top)
		.HAlign(HAlign_Center)
		.Padding(5)
		.IsEnabled_Static(&Locals::IsWidgetEnabled)
		
			SNew(SVerticalBox)
			+SVerticalBox::Slot()
			.VAlign(VAlign_Top)
			.HAlign(HAlign_Left)
			.Padding(5)
			
				SNew(SEditableTextBox)
				.Text(this, &FGridToolsEdModeToolkit::GetRadius)
			]
		];
}

void FGridToolsEdModeToolkit::SetRadius(const FText& InText)
{
	FString tempString = InText.ToString();
	FGridToolsEdModeToolkit::Radius = FCString::Atoi(*tempString);
}

FText FGridToolsEdModeToolkit::GetRadius() const
{
	return FText::FromString(FString::FromInt(FGridToolsEdModeToolkit::Radius));
}



Crash error info:


 Assertion failed: SharedThis.Get() == this [File:D:\GitHub\UnrealEngine\Engine\Source\Runtime\Core\Public\Templates\SharedPointer.h] [Line: 1093] 
 
 
 
 KERNELBASE.dll
 UE4Editor-Core.dll!FOutputDeviceWindowsError::Serialize() [d:\github\unrealengine\engine\source\runtime\core\private\windows\windowsplatformoutputdevices.cpp:102]
 UE4Editor-Core.dll!FOutputDevice::Logf__VA() [d:\github\unrealengine\engine\source\runtime\core\private\misc\outputdevice.cpp:154]
 UE4Editor-Core.dll!FDebug::AssertFailed() [d:\github\unrealengine\engine\source\runtime\core\private\misc\outputdevice.cpp:440]
 UE4Editor-UnrealEd.dll!TSharedFromThis<FModeToolkit,0>::AsShared() [d:\github\unrealengine\engine\source\runtime\core\public	emplates\sharedpointer.h:1097]
 UE4Editor-GridTools.dll
 UE4Editor-GridTools.dll
 UE4Editor-GridTools.dll
 UE4Editor-GridTools.dll
 UE4Editor-UnrealEd.dll!FEditorModeTools::ActivateMode() [d:\github\unrealengine\engine\source\editor\unrealed\private\editormodemanager.cpp:361]
 UE4Editor-LevelEditor.dll!SLevelEditor::ToggleEditorMode() [d:\github\unrealengine\engine\source\editor\leveleditor\private\sleveleditor.cpp:1240]
 UE4Editor-LevelEditor.dll!TBaseStaticDelegateInstance<void __cdecl(void),FName>::ExecuteIfSafe() [d:\github\unrealengine\engine\source\runtime\core\public\delegates\delegateinstancesimpl_variadics.inl:1021]
 UE4Editor-Slate.dll!FUICommandList::ExecuteAction() [d:\github\unrealengine\engine\source\runtime\slate\private\framework\commands\uicommandlist.cpp:87]
 UE4Editor-Slate.dll!SToolBarButtonBlock::OnClicked() [d:\github\unrealengine\engine\source\runtime\slate\private\framework\multibox\stoolbarbuttonblock.cpp:300]
 UE4Editor-Slate.dll!SToolBarButtonBlock::OnCheckStateChanged() [d:\github\unrealengine\engine\source\runtime\slate\private\framework\multibox\stoolbarbuttonblock.cpp:326]
 UE4Editor-Slate.dll!TBaseSPMethodDelegateInstance<0,SToolBarButtonBlock,0,TTypeWrapper<void> __cdecl(enum ECheckBoxState)>::Execute() [d:\github\unrealengine\engine\source\runtime\core\public\delegates\delegateinstancesimpl_variadics.inl:321]
 UE4Editor-Slate.dll!TBaseSPMethodDelegateInstance<0,SToolBarButtonBlock,0,void __cdecl(enum ECheckBoxState)>::ExecuteIfSafe() [d:\github\unrealengine\engine\source\runtime\core\public\delegates\delegateinstancesimpl_variadics.inl:428]
 UE4Editor-Slate.dll!SCheckBox::ToggleCheckedState() [d:\github\unrealengine\engine\source\runtime\slate\private\widgets\input\scheckbox.cpp:293]
 UE4Editor-Slate.dll!SCheckBox::OnMouseButtonUp() [d:\github\unrealengine\engine\source\runtime\slate\private\widgets\input\scheckbox.cpp:184]
 UE4Editor-Slate.dll!<lambda_8d0e9a1da76abd0a756a3a9d775f5ed1>::operator()() [d:\github\unrealengine\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:4598]
 UE4Editor-Slate.dll!FEventRouter::Route<FReply,FEventRouter::FToLeafmostPolicy,FPointerEvent,<lambda_8d0e9a1da76abd0a756a3a9d775f5ed1> >() [d:\github\unrealengine\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:215]
 UE4Editor-Slate.dll!FSlateApplication::RoutePointerUpEvent() [d:\github\unrealengine\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:4587]
 UE4Editor-Slate.dll!FSlateApplication::ProcessMouseButtonUpEvent() [d:\github\unrealengine\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:5041]
 UE4Editor-Slate.dll!FSlateApplication::OnMouseUp() [d:\github\unrealengine\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:5021]
 UE4Editor-Core.dll!FWindowsApplication::ProcessDeferredMessage() [d:\github\unrealengine\engine\source\runtime\core\private\windows\windowsapplication.cpp:1510]
 UE4Editor-Core.dll!FWindowsApplication::DeferMessage() [d:\github\unrealengine\engine\source\runtime\core\private\windows\windowsapplication.cpp:1850]
 UE4Editor-Core.dll!FWindowsApplication::ProcessMessage() [d:\github\unrealengine\engine\source\runtime\core\private\windows\windowsapplication.cpp:745]
 UE4Editor-Core.dll!FWindowsApplication::AppWndProc() [d:\github\unrealengine\engine\source\runtime\core\private\windows\windowsapplication.cpp:667]
 USER32.dll
 USER32.dll
 UE4Editor-Core.dll!FWindowsPlatformMisc::PumpMessages() [d:\github\unrealengine\engine\source\runtime\core\private\windows\windowsplatformmisc.cpp:903]
 UE4Editor.exe!FEngineLoop::Tick() [d:\github\unrealengine\engine\source\runtime\launch\private\launchengineloop.cpp:2729]
 UE4Editor.exe!GuardedMain() [d:\github\unrealengine\engine\source\runtime\launch\private\launch.cpp:148]
 UE4Editor.exe!GuardedMainWrapper() [d:\github\unrealengine\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
 UE4Editor.exe!WinMain() [d:\github\unrealengine\engine\source\runtime\launch\private\windows\launchwindows.cpp:200]
 UE4Editor.exe!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:255]
 kernel32.dll
 ntdll.dll
 ntdll.dll

Line 1093 of SharedPointer.h is:


TSharedRef< ObjectType, Mode > AsShared()
	{
		TSharedPtr< ObjectType, Mode > SharedThis( WeakThis.Pin() );

		//
		// If the following assert goes off, it means one of the following:
		//
		//     - You tried to request a shared pointer before the object was ever assigned to one. (e.g. constructor)
		//     - You tried to request a shared pointer while the object is being destroyed (destructor chain)
		//
		// To fix this, make sure you create at least one shared reference to your object instance before requested,
		// and also avoid calling this function from your object's destructor.
		//
		check( SharedThis.Get() == this );

		// Now that we've verified the shared pointer is valid, we'll convert it to a shared reference
		// and return it!
		return SharedThis.ToSharedRef();
	}

Any ideas what could be wrong ?

The answer is there in the comment above the assert :slight_smile:
You can’t use SharedThis() from within a constructor. I know you haven’t used it explicitly, but the .Text() call expects a shared pointer, so it’s called implicitly when you pass this.

You need to either delay registering your delegate until somewhere post-constructor, or use a different type of binding - Text_Lambda or Text_Raw.

Changing attributes type to .Text_Raw and .OnTextChanged_Raw fixed the crash and everything works perfectly. Thank you very much :slight_smile: