[bug] UWidget::SetUserFocus

Hi,

I show a widget when the controller of a user is disconnected. To ensure keyboard focus i use the method setuserfocus. The funny thing is that the method setuserfocus uses the connected controller index, which at that time is of course disconnected… and returns -1, which will eventually lead to an incorrect array index. The fact that the code comments says its a hack triggered me that this is not really nice :slight_smile:

UWidget::SetUserFocus(APlayerController* PlayerController)
{
.....

    // HACK: We use the controller Id as the local player index for focusing widgets in Slate.
    int32 UserIndex = LocalPlayer->GetControllerId();

....
}

…

Hey ,

I have a few questions that can help with reproducing this issue:

  • Do you have an example case that we can use to reproduce this on our end?
  • Are you experiencing a crash at all when this issue occurs? If so, could you provide the logs from your project’s Saved->Logs folder?

the Crash occurs at the following line:

bool FSlateApplication::SetUserFocus(const uint32 InUserIndex, const FWidgetPath& InFocusPath, const EFocusCause InCause)

check(InUserIndex >= 0 && InUserIndex < SlateApplicationDefs::MaxUsers);

Due to the InUserIndex being equal to -1 when no controller is connected. In my case i am playing on PC with an xbox controller connected that i pull out of the usb port and right at that instant the controller id is temporarily -1 which crashes the game if i also set focus to some widget at that time.

  • Could you please provide the logs from your project’s Saved->Logs folder after the crash occurs?
  • If you are getting a Crash Reporter window, please provide your Machine ID and ensure to hit Send & Close on the report.

Hello,

I am marking this topic as resolved for tracking purposes, as we have not heard from you in a few days. If this issue persists, feel free to respond to this thread. For any new issues, please create a new Answerhub topic.

Have a great day