Crash when rapidly adding and removing uwidget from viewport, being called by async line trace
I finished programming an interact system for unreal which uses the async linetrace function to determine if an appropriate actor has been looked at, and then uses the player controller to call the addtoviewport function in a widget class which inherits from UUser widget and is connected to a widget blueprint. This works exactly as expected, when I look at an appropriate actor it adds the text prompt to the screen and when I look away it removes it (I also programmed this functionality, basically the same thing but with removefromviewport). But then I noticed that when I quickly look at an appropriate object and then away over and over at a quick pace, it causes the game to crash stating: Access violation - code c0000005 (first/second chance not available) when calling UE4Editor_UMG!UUserWidget::AddToViewport(). Problem is that all calls from pointers occur after the pointer is check to make sure it is not a nullptr, so this error shouldn't be possible. Does anyone have an idea why this is happening?
Update: I have check and this error still occurs when non-async line trace is called.
There is, I worked it out. If you dont declare holding variables as uproperties the trash collector will delete it while it's still in use. Then when that variable is called it crashed it. In this case its the uuserwidget variable
answered Apr 14 '19 at 07:51 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here