Calling UWorld::LineTraceSingle with a NULL this pointer fails silently

UWorld* NullWorld = nullptr;
NullWorld->LineTraceSingle(…); // runs without issue, returns false

In this case, the RaycastSingle function in PhysXCollision.cpp simply early outs with a return value of false. This bit me recently and I wasted more time debugging it than I care to admit!

It seems like both overloads of UWorld::LineTraceSingle should probably assert this != nullptr to defuse this insidious gotcha.

Hi ,

Thank you for your report. I will begin investigation into this issue as soon as possible. If I am unable to reproduce the problem, or I need more information, I or another staff member will follow up with some additional questions for you. Otherwise, I will post an ‘Answer’ once I have logged the issue in our bug database or we have a solution for it.

In the meantime, please be sure to review our suggestions for how to report a bug, and feel free to edit your post if you have additional information to provide:

Hi ,

I am very sorry for not getting back to this post sooner. I have submitted a feature request asking if it would be possible to provide some feedback to the user when RaycastSingle() fails because UWorld is NULL (TTP# 348962).

I think the fact that C++ actually tries to execute a function on a NULL pointer is a very unfortunate ‘feature’. That should be an immediate crash IMO, and it should be up to the caller to ensure the pointer is valid before calling a pointer on it :slight_smile: I see your point about asserting that ‘this’ is valid, but that would set a precedent that all functions should do that, and I don’t think that is practical.