Crash after second Play

Everytime I click Play for the second time in the editor it crashes. Then when I open it again and click Play it works well, and then when I click Play again it crashes once more.

It’s difficult to tell exactly when this start hapening since I use to experience lot of crashes in the editor every day.

I started using the funcion IsValid just in case of pointers, instead of just != NULL
I mentioned this because that’s one of the things I found on the report, but it says ((UObject*)ContainerPtr)->IsValidLowLevel() Actually I just use IsValid( myPointer ).

Here’s one of the reports:

Assertion failed: ((UObject*)ContainerPtr)->IsValidLowLevel() [File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.5\Engine\Source\Runtime\CoreUObject\Public\UObject\UnrealType.h] [Line: 343] 

KERNELBASE + 24684 bytes
UE4Editor_Core + 3174852 bytes
UE4Editor_Core + 1677512 bytes
UE4Editor_Core + 1566866 bytes
UE4Editor_CoreUObject + 1569207 bytes
UE4Editor_CoreUObject + 1435554 bytes
UE4Editor_CoreUObject + 1435510 bytes
UE4Editor_CoreUObject + 1440718 bytes
UE4Editor_CoreUObject + 1320058 bytes
UE4Editor_CoreUObject + 1577556 bytes
UE4Editor_CoreUObject + 1440718 bytes
UE4Editor_CoreUObject + 1320058 bytes
UE4Editor_CoreUObject + 1577556 bytes
UE4Editor_CoreUObject + 1440718 bytes
UE4Editor_CoreUObject + 549780 bytes
UE4Editor_CoreUObject + 1438659 bytes
UE4Editor_Engine + 1818193 bytes
UE4Editor_Engine + 17252682 bytes
UE4Editor_Engine + 1912026 bytes
UE4Editor_Engine + 6461726 bytes
UE4Editor_Engine + 1912542 bytes
UE4Editor_Engine + 1652387 bytes
UE4Editor_Engine + 8779958 bytes
UE4Editor_Engine + 8829659 bytes
UE4Editor_Core + 746772 bytes
UE4Editor_Core + 747165 bytes
UE4Editor_Core + 870341 bytes
UE4Editor_Engine + 9060549 bytes
UE4Editor_Engine + 8971673 bytes
UE4Editor_Engine + 8982533 bytes
UE4Editor_Engine + 5590422 bytes
UE4Editor_Engine + 5619151 bytes
UE4Editor_UnrealEd + 1895346 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]

My specs are:
Windows 8.1,
i5-2400,
12gb Ram,
AMD 6870

Hey -

Does the same crash behavior occur in a new blank project with nothing added as well? If you could also add the logs and dump file from the crash it will help tell us where the problem is. The files should be saved in the project folder inside the Saved->Logs folder. These are updated each time the editor is run so you’ll want to have the crash happen and then get the most recent files after it closes.

Cheers

So, I managed to fix this by removing any kind of static things in code.

I used them for managers but, after talking to ( Random crashes in editor showing own code - Programming & Scripting - Epic Developer Community Forums ), I started to make some tests and got this resolved.

So looks like Unreal doesn’t like static methods or static variables, because I wasn’t able to declare them with UFUNCTION and UPROPERTY and without those the crashes appear; but after removing them at all (and referencing the instances with Iterators in the scene), the crash stop happening.

Hope this help as feedback at least.

Hi ,

So I moved backwards and managed to reproce the crash again in an empty level.

I only added to the scene PlayerManager and GlobalManager. The first one is to include the player when it’s created and the second one is a reference that must of objects use to link to other managers. In this case, the Player looks for GlobalManager to get in contact with the PlayerManager, so it can be added to an array.

Since the player is created in real time, I decided to use a static method in GlobalManager called Get() which returns a static instance of itself (_instance). That instance is filled with the GlobalManager mentioned from the scene during the constructor.

Once the player spawns he starts searching for the GlobalManager in the next function during the Tick:

void APLPlayer::CheckManagers ()
{
	if ( !IsValid( _globalManager ) )
		_globalManager = APLGlobalManager::Get();

	if ( IsValid( _globalManager ) && IsValid( _globalManager->_playerManager ) )
		_globalManager->_playerManager->AddPlayer( this );
}

I made a test by creating an empty Player with only this function called in blueprint from the Tick. And the crash hapends as before when the game Plays for the second time.

Just in case, here are the codes Managers in short:

GlobalManager

.h

UCLASS( Meta=(ChildCanTick) )
class PROYECTOLOCO_API APLGlobalManager : public AActor
{
	GENERATED_UCLASS_BODY()

	static APLGlobalManager * Get() { return _instance; }

private:

	static APLGlobalManager * _instance;
};

.cpp

APLGlobalManager * APLGlobalManager::_instance = NULL;

APLGlobalManager::APLGlobalManager(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	PrimaryActorTick.bCanEverTick = true;
	PrimaryActorTick.bStartWithTickEnabled = true;
	PrimaryActorTick.bAllowTickOnDedicatedServer = true;
}

bool APLGlobalManager::BelongToCurrentLevel ()
{
	if ( _worldManager == NULL )
		return true;
	
	if ( _levelName == _worldManager->_worldName )
		return true;

	return false;
}

PlayerManager

.h

UCLASS( Meta=(ChildCanTick) )
class PROYECTOLOCO_API APLPlayerManager : public AActor
{
	GENERATED_UCLASS_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Players)
	TArray <APLPlayer*> _players;

	UFUNCTION(BlueprintCallable, Category = Players)
	void AddPlayer ( APLPlayer * _newPlayer );
};

.cpp

APLPlayerManager::APLPlayerManager(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
}

void APLPlayerManager::AddPlayer ( APLPlayer * _newPlayer )
{
	if ( _players.Contains( _newPlayer ) )
		return;

	_players.Add( _newPlayer );
}

Sorry, wrong version of the GlobalManager.
Here’s the one used for the crash:

.h

UCLASS( Meta=(ChildCanTick) )
class PROYECTOLOCO_API APLGlobalManager : public AActor
{
	GENERATED_UCLASS_BODY()

	static APLGlobalManager * Get() { return _instance; }

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Level)
	FName _levelName;
	
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Managers)
	APLAreaManager * _areaManager;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Managers)
	APLAudioManager * _audioManager;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Managers)
	APLPlayerManager * _playerManager;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Managers)
	APLWorldSettings * _worldManager;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Managers)
	APLGlobalVariables * _globalVariables;

	virtual void Tick ( float deltaTime ) override;

private:
	
	static APLGlobalManager * _instance;
};

.cpp

APLGlobalManager * APLGlobalManager::_instance = NULL;

APLGlobalManager::APLGlobalManager(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	PrimaryActorTick.bCanEverTick = true;
	PrimaryActorTick.bStartWithTickEnabled = true;
	PrimaryActorTick.bAllowTickOnDedicatedServer = true;
}

void APLGlobalManager::Tick ( float deltaTime )
{
	Super::Tick( deltaTime );

	if ( (APLGlobalManager::_instance == NULL) && ((_worldManager == NULL) || ((_worldManager != NULL) && (_levelName == _worldManager->_worldName))) )
		APLGlobalManager::_instance = this;
}

And here are the reports you requested me:
https://dl.dropboxusercontent.com/u/17675347/UE4CrashReoprt.rar

Hey Tobias-

Does the crash occur for you if you don’t add the GlobalManager and PlayerManager to a new project?

Hi ,

I was able to reproduce a crash very similar to what you described here (the callstack is slightly different, but that may be because of slight changes I made to build the code). I will be taking another look at this issue tomorrow, but I was hoping you could confirm something for me. If you remove the call to your CheckManagers function in the Player class, do you still see the crash happen the second time you click the Play button?

Hey ,

So, I’ve just tryed that. The crash stops hapenning when I remove the static call from the Player, like this:

void APLPlayer::CheckManagers ()
 {
     //if ( !IsValid( _globalManager ) )
     //    _globalManager = APLGlobalManager::Get();
 
     if ( IsValid( _globalManager ) && IsValid( _globalManager->_playerManager ) )
         _globalManager->_playerManager->AddPlayer( this );
 }

If I remove the other two lines (but the firsts two), the crash hapens again.
So, looks like it’s something related with the static calls.

Nope, if I remove both managers from the scene the crash doesn’t ocurr.
Looks like It’s related to this static call from the Player, as I mentioned to :

if ( !IsValid( _globalManager ) )
    _globalManager = APLGlobalManager::Get();

If I remove that, the crash dissapears.

Hi ,

I did a little more investigation into this issue this morning, and was able to get some information that may be helpful to you, as well as future users who may run into this issue.

Unfortunately using static methods and variables within Unreal Engine 4 is not a particularly safe practice. It is not impossible, but statics are essentially invisible to the Engine’s garbage collection system, and can lead to completely unexpected behavior (crashes, stale values, inability to unload levels, etc).

A suggestion that would possibly work better within the Engine would be to place the variables in WorldInfo, GameMode, or GameInstance, depending on your needs.

Hey. Im having similar issue when using Tmultimap. The editor crashes when I run the game for second time. However, Tmultimap data persists during the entire gameplay (when running it for the first time), so the Tmultimap obviously does not get removed during the first run. During the second run, the editor crashes once the game tries to access Tmultimap.
I need the Tmultimap to persist during the whole gameplay (until the game does not quit) - as it does during the first gameplay. However, I cannot define Tmultimap with Uproperty (it wont compile if I attempt to).

Can this be the reason why the game crashes the second time? How can we declare Tmultimaps so that they do not get garbage collected and persist throughout gameplay?

THANKS IN ADVANCE :slight_smile:

Hello,
Today I packaged a heavy game and the “second” time that I wanted to run it it crashed. (D3D error)
My only option was to restart my PC. Then again, I could only open it once till I restarted the machine again.

Then I realized if I exit epic games on the “system tray” I can run my game for as many times as I want without having to restart my computer. cheers.

Hope it helps you too.

hello,
Sorry to revie an old topic but have issues here the same thing keeps on happing to me as for removing static members of any kind there is a problems though the blueprint function library needs to have static functions doesnt it? what should i do about that?