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 ).
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.
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.
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.
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?
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();
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?
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.
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?