Blueprints: Map, Bug in Contains-Function?

Hi there,

I currently implement that names of players are shown above their heads so that the names have the same size no matter how far away their characters are. So I don’t want to use 3D Widgets :wink:

I already got this working as you can see:

And here is (partly) how I implemented it:

My BeginPlay- and EndPlay-events of my characters execute a function in my gamestate and further execute a corresponding multicast-delegate.
The gamestate has multicast-delegates for the BeginPlay- and EndPlay-events so that anybody who wants to know if a certain character spawned or was destroyed can be informed by subscribing to those two delegates.

My playernames are organized in two widget classes: 1 Manager-Widget-Class and 1 Name-Display-Widget-Class.
The Manager-Widget listens to the two multicast-delegates from my gamestate and spawns or removes the corresponding Name-Display-Widgets.

To remember the corresponding Name-Display-Widgets for my Characters I store them in the map.
In the tick event I access them in a separate array since arrays seem to be more stable when removing or dynamically adding objects while accessing them in the tick function. Hence, the map is only used as a lookup-table which uses the character/pawn as key and the Name-Display-Widget as value and is not touched in the tick function.

So when a character executes its BeginPlay-Event the following graph is executed:

[(Alternative Link for Blueprint-View)][3]

And for the EndPlay-Event, the following graph is executed:

[(Alternative Link for Blueprint-View)][5]

The EndPlay is in my case triggered because the player left with its character the replication range of the clients.
This setup works perfectly fine at the start of the game.

In most cases, leaving the replication range of the clients with the Listen-Server-Character worked fine.
So the Remove-Widget-Graph seems to work.
However, as soon as I enter the replication range again with the Listen-Server-Character, I get the following error: [See here (pastebin)][6]

There it is stated that my propagated Begin-Play-Event caused an error in a Contains-Block.
To be more precise, it ends with:

UE4Editor_CoreUObject!UObjectPropertyBase::Identical() [d:\build++ue4+release-4.15+compile\sync\engine\source\runtime\coreuobject\private\uobject\propertybaseobject.cpp:63]

If we now look up the code (see below) the error occurs when the classes of the objects are compared.

bool UObjectPropertyBase::Identical( const void* A, const void* B, uint32 PortFlags ) const
{

...

	if (!ObjectA || !ObjectB)
	{
		return false;
	}

...

	if (!bResult && ObjectA->GetClass() == ObjectB->GetClass()) //Error occurs here!
	{

...

}

I also tested this in Debug-Mode and then it was stated that “This variable was optimized away”. This might refer to the key already stored in the map.

I don’t get how the previous check “if (!ObjectA || !ObjectB)” would still work while the error only occurs later on…

TL;DR: I have a map using replicated pawns as keys and widgets as values. If a pawn is not relevant anymore (leaves replication range), it is removed from the map. If a pawn is again relevant, it is again added to the map. While this sometimes works, I receive an error if an already existing object reenters(added->removed->added) the replication range of the clients and my whole game crashes.
I believe the reason for that is the Contains/Find-Block of Maps but I don’t understand why this happens. Maybe because I use replicated pawn references as keys but on the other side I remove those references from the map before their corresponding pawn is destroyed.

Question is: Is this intended behavior or a bug?

//Edit: I just tried to replace my keys, the replicated pawn references with their object-names. So my map would be String->Widget. This results in the same error.

//Edit2: I just tried to recreate this error only with Blueprints in a minimalist version. [(Github-Link)][7] However, this version seems to work fine. I also tried to compile and run my original project in DebugEditor-Mode but this still caused the same error.

Hey smara,

After reading over your thread, I’m not sure what could be causing the issue on your end. It is strange that when you recreated the minimalist version, you didn’t run into the same error. It’s tough to diagnose and reproduce the issue without a clear idea of what could be causing it.

I recommend that you attempt to add some more features of the original version to the minimalist version you created until you run into the issue again. I think this would be the best approach as far as attempting to discover what is causing the issue.

Unfortunately, I’m limited as far as what action I can take with this until we have identified a way to reproduce the issue so that I can perform some tests.

Let me know if you come across any additional information that we can use to reproduce this.

Thanks

Hi there,

finally I could reproduce it :slight_smile:
I also updated my github project. [(Github-Link)][1]

So, this time I used a Set instead of a map, but they behave roughly the same.
I created 2 functions. One which fills the set, the other empties it.
Since I didn’t check if the To-Array function from the set really creates a safe copy, I used my own.

In my tests, this error occurs more often when larger numbers of elements are used. However, it can also happen for just some items.

To reproduce do the following:

  1. Press T several times, which will create 250 objects. At best do it several times.
  2. Press B once to basically empty that set.
  3. Press T again, to again create several objects and add them to the set. Here the error occurs and the editor crashes.

If you cannot reproduce it, please tell me and I will upload a video.

Here again, the crash Log:

Hey,

Sorry for the delay on this. I’ve tested it, and I’ve reproduced the crash in 4.15. However, after testing in the newly-released 4.16 Preview, I’m not seeing the crash, so it may be resolved. Would you mind testing a bit in the Preview to see if you can reproduce the crash there?

I couldn’t find a ticket in our database related to this crash unfortunately, so if it is fixed, I won’t be able to provide a specific commit.

Hi,

I just tried it in 4.16 Preview for a Set of UObjects and a Map of UObject->Integer.

I couldn’t reproduce this error anymore. Though I am curious why the issue suddenly disappeared.