HandleMatchHasStarted : Assertion failed: !DelegateInstanceInterface->IsSameFunction(*InDelegateInstance)

Hi,

I have a custom gamemode that make the match play by round.
At the beginning of each round, I’m calling HandleMatchHasStarted to properly reset & restarting my round without reloading the level.

In 4.7, evertyhing was workign as expected. Since 4.8, I have this issue:
Assertion failed: !DelegateInstanceInterface->IsSameFunction(*InDelegateInstance) [File:c:\unreal engine\4.8\engine\source\runtime\core\public\delegates\DelegateSignatureImpl_Variadics.inl] [Line: 1003]

The issue is raised on the 2nd Round.

The code is doing:
AGameMode::HandleMatchHasStarted()
which call GameSession->HandleMatchHasStarted();
which set StartSessionCompleteHandle = SessionInt->AddOnStartSessionCompleteDelegate_Handle(FOnStartSessionCompleteDelegate::CreateUObject(this, &AGameSession::OnStartSessionComplete));

On the first call it’s working as expected, but on the 2nd call the assertion failed.
It seems that the old delegate and the new one is not the same, but I can’t get what’s wrong.

Thanks for your help in debug/fixing this.

Hi,
Are you able to repro this ?
Is this somethign known?

Thanks,

Hi,

you put this change live in 4.8 without any notification:
https://github.com/EpicGames/UnrealEngine/commit/79e183780fb912ba059d04148260fc404fc83b65

I can understand that It’s interesting, but it can have side effect for anyone that is working with a OnlineServices.

I still don’t know why the Delegate issue is raising, but now I understand why it appears in 4.8 and not in 4.7.

I would really apreciate if you can tell me if you have been able to repro the issue on your side.

Thanks,

Hi Elvince,

The error message that you provided matches a crash that we have received multiple reports about. We believe we have a fix in place for this crash, but do not yet have any solid repro steps to test with. Would you be able to provide some additional information about how you are setting up and using your delegates, or would it be possible to take a look at your project?

Tim

Hi Tim,

In fact, it’s the Engine code that is setuping the delegate:
It’s in : GameSession->HandleMatchHasStarted()

In my code,the delegate is not cleared between 2 calls to HandleMatchHasStarted() as this state is called twice without calling endmatch (which clear the delegate).
Just try to call this function twice with an OnlineServices Setup.

I hope your can put a repro in place with thoses informations.

Hi,
have you been able to repro this?
Do you need more information?

thanks,

I don’t know if this is the same bug, but I am getting the same error when trying to bind to a delegate, as well. Would this code help reproduce it, if it is an associated issue? https://answers.unrealengine.com/questions/259246/how-to-properly-bind-to-multicast-non-dynamic-dele.html

I was encountering a similar issue (with a different delegate), and after a while of struggling, I finally figured out that my problem was simply that I was binding to the delegate twice. Since this is happening on the second round, this is probably your issue. Either call Remove() at the end of the first round to unbind the first delegate, or just add a condition to not set the receiving delegate a second time.

The issue is exactly this and this is why I reported it.

When you set twice the same delegate without a remove you have the error message.

thanks,

Hi Elvince,

Very sorry for the delay on this post. Checking into this a little bit further, it looks like the Engine itself is calling HandleMatchHasStarted(), and then your custom GameMode class calls it again (or vice versa). Ideally, the call to this function from the Engine should be sufficient. If that is not the case, that is something else we may have to take a look at.

Our concern at the moment is not that the delegates are different, but that it may be trying to bind a delegate that is already bound. The code does appear to be trying to clear the delegate when it is complete, so it looks like there may be a code path that isn’t properly triggering the delegate. What platform are you working on currently?

Tim

Hi,

I know the root cause of the issue.
It’s a change that has been implemented in 4.8 so I had to rework on my source code to manage this new “base behavior”.

So on my side I fixed the issue.

I’m working on a PC Platform. I just called multiple time StartMatch before endmatch because I was using this to manage Round inside a match.
It’s was working perfectly in 4.7 because there was no default behavior for those function (see link in 3rd comment).
So the delegate is already bind at the first Call (1st Round) and call again at the 2nd Round (without end game - means no remove binding).

Thanks,

I tried reproducing this using various multiplayer options by setting up a keypress to call HandleMatchHasStarted(), then pressing that key multiple times. It did not trigger the assertion for me. Would it be possible to see the code for your custom GameMode class?

Tim

Hi Elvince,

We have not heard back from you for a few days. Are you able to provide any additional information that would help us repro this issue? Since you have found a solution for your own project, I will mark this as resolved for internal tracking purposes, but I will continue to poke at this issue periodically to see if I can repro it. If you do have any additional information that would help, please feel free to add a comment to this post and re-open it.

Tim

Sorry I had no time to get a repro available.
There is a problem somewhere as I’m not alone to have this issue but it’s not easy to repro ^^
If I can get one I will submit it.

thanks for your time.

[Apologies if duplicates of this get posted; answerhub seems to be functioning strangely and I’m not sure if my posts are showing up].

I get this same error. I had a working game in UE 4.7, upgraded to 4.9, fixed C++ compile errors, tried to play and immediately got this error.

I am using a C++ game mode and then inheriting from that in a blueprint game mode. The game modes do not do anything complicated. Basically just setup some debugging stuff.

I tried re-parenting my game mode so it inherits from GameMode and does not use my C++ game mode. It still crashes on startup.

Further investigation suggests that for me it is not the GameMode that is the problem. Instead, when I use Event Begin Play in the player controller, create some UMG widgets (including using UserWidget), and then call AddToViewport in the player controller begin play it crashes with this error.

The crash log also mentions

UE4Editor_UMG!UUserWidget::AddToScreen() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\umg\private\userwidget.cpp:490]

Digging further helped me realize that I was calling AddToViewport twice: once in the player controller after crating my UserWidget and another time in the OnConstruct event of the UserWidget. Obviously that was something I was doing wrong, but it would be really nice to have a better error message or not crash.

Hope this is helpful for you guys.

Thanks,
-X

Hi Xarol,

Thank you for the additional information that you provided. I was able to reproduce a crash that provided the exact same error message that Elvince mentioned in his initial post. I am not sure that this is the exact crash that Elvince was experiencing without being able to compare callstacks, though. However, it is most likely very similar. The fix that I mentioned in my first comment did not prevent this crash, so I have entered a report about this crash to have it investigated further (UE-20873). For a workaround, make sure that any particular instance of a UMG widget is only added to the viewport once.

Elvince, if you get a chance, would it be possible to get the callstack for the crash that you were initially experiencing? Don’t worry about it if you can’t.

Tim

Hi,

I can’t get the stackstrace as I fixed this in my code to not “crash”.

Clearly, from reading, it’s the same issue. Something that you are calling twice that should not be call twice without another function call in between that “clean the stuffs”.

Great that we have a repro now!

Thanks,