Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

UWidget::IsHovered causes a crash.

We have a custom UWidget class that represents an item in a menu. There are two places where we call IsHovered on that class and they both crash seemingly randomly.

In the UUserWidget subclass that contains the menu items we iterate over them to see which one is selected using this code:

 UMenuItem* NewSelection = nullptr;
 for (UMenuItem* MenuItem : Children)
     if (MenuItem->IsHovered())
         NewSelection = MenuItem;

Randomly it crashes on the MenuItem->IsHovered() line with an error that says MenuItem is nullptr but when it breaks we can inspect it and it's not a nullptr and everything in the callstack looks good.

The other place that it crashes is in the UMenuItem class itself. In the tick method we just have some code that checks whether it's hovered and updates the highlight state of the widget.

 Hovered = IsHovered();

When the crash happens here it says this-> is nullptr but again we can inspect when it breaks and see that this is not the case. We can even step up the callstack and verify that the list that's holding the menu items looks good.

Has anyone seen a crash like this before?

Product Version: UE 4.21
more ▼

asked Mar 28 '19 at 05:01 PM in C++ Programming

avatar image

1 1 1

avatar image emperor_katax Mar 29 '19 at 04:52 AM

…. you may check if your MenuItem is not a null value. Mostly sudden crashes caused by access null objects, in your case, it may try to execute ->IsHovered() and it end up with null->IsHovered() and then , crashed. ..


 if (MenuItem != nullptr) {
    if (MenuItem->IsHovered())
          NewSelection = MenuItem;
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question