Download

[UE 4.7]: SetTimer in custom Editor Plugin is crashing Engine?

Hi!

I want to have a time ticker in my custom Editor plugin.

My code is very, very simple in .cpp:


#include "timerPluginPch.h"
#include "Module.h"
#include "LevelEditor.h"
#include "UnrealEd.h"

IMPLEMENT_MODULE(Module, timerPlugin);
DEFINE_LOG_CATEGORY(ModuleLog)

Module::Module()
{
}

void Module::StartupModule()
{
	UE_LOG(ModuleLog, Warning, TEXT("*** Hi from Timer Plugin! ***"));

	float Seconds = (float)FTimespan::FromMinutes(0.1).GetTotalSeconds();
	FTimerDelegate Delegate;
	Delegate.BindRaw(this, &Module::Ticker);

	GEditor->GetTimerManager()->SetTimer(TimerHandle_Ticker, Delegate, Seconds, true);
}

void Module::ShutdownModule()
{
}

void Module::Ticker()
{
	UE_LOG(ModuleLog, Warning, TEXT("--- T I C K ---"));
}

My header:


#pragma once

DECLARE_LOG_CATEGORY_EXTERN(ModuleLog, Log, All)

class Module : public IModuleInterface
{
public:
	Module();

	virtual void StartupModule() override;
	virtual void ShutdownModule() override;

private:
	FTimerHandle TimerHandle_Ticker;
	void Ticker();
};

I am trying to follow Rama’s post “FTimerHandle / Timers in 4.7 and existing code of UnrealEdMisc.cpp in Editor source.

I can build my code but getting crash with Unreal start.

Would you be so kind to correct my code to avoid this please?

Thank you in advance!

Crash report data:


MachineId:36E9615D472586C10EF897AB71700626
EpicAccountId:2b6f31d4f0834a3fa50389ca349e5461

Access violation - code c0000005 (first/second chance not available)

UE4Editor_UnrealEd!TSharedPtr<FTimerManager,0>::ToSharedRef() + 38 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\core\public	emplates\sharedpointer.h:616]
UE4Editor_UnrealEd!UEditorEngine::GetTimerManager() + 29 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\editor\unrealed\classes\editor\editorengine.h:1710]
UE4Editor_timerPlugin!Module::StartupModule() + 312 bytes [c:\users\vyudin\documents\unreal projects	imers\plugins	imerplugin\source	imerplugin\private\module.cpp:21]
UE4Editor_Core!FModuleManager::LoadModuleWithFailureReason() + 2426 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\core\private\modules\modulemanager.cpp:371]
UE4Editor_Projects!FModuleDescriptor::LoadModulesForPhase() + 784 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\projects\private\moduledescriptor.cpp:350]
UE4Editor_Projects!FPluginManager::LoadModulesForEnabledPlugins() + 753 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\projects\private\pluginmanager.cpp:424]
UE4Editor!FEngineLoop::LoadStartupModules() + 730 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\launch\private\launchengineloop.cpp:1863]
UE4Editor!FEngineLoop::PreInit() + 11141 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\launch\private\launchengineloop.cpp:1400]
UE4Editor!GuardedMain() + 251 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\launch\private\launch.cpp:110]
UE4Editor!GuardedMainWrapper() + 26 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor!WinMain() + 249 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\launch\private\windows\launchwindows.cpp:202]
UE4Editor!__tmainCRTStartup() + 329 bytes [f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c:618]