When using CastChecked<>(), the second parameter can be passed as ECastCheckedType::NullAllowed to make the check succeed when the input is nullptr. However, in UE 5.5 up to the latest engine version, passing a nullptr crashes in builds where the DO_CHECK macro is set to zero (e.g. shipping and testing builds). The crash happens consistently when the cast is to an interface.
This regression is probably caused by CLs 35133078 and 35245469. The pair of macros FUNCTION_NON_NULL_RETURN_START/END annotate a function as never returning nullptr, so the change made by those CLs is correct at first inspection. However, the internal test "if (!Src) return nullptr;" should probably have been moved to the version of CastChecked() that takes ECastCheckedType::Type CheckType as a parameter (instead of simply removed altogether), since nullptr is indeed a valid return for it.
=== REPRO PROJECT ===
=== BLANK PROJECT ===
1. Create a C++ interface UMyInterface / IMyInterface
2. Create a C++ class UMyImplementor derived from the interface
3. Create a C++ actor
3.1. On the BeginPlay() method:
IMyInterface* MyInterface = CastChecked<IMyInterface>(nullptr, ECastCheckedType::NullAllowed);
4. Compile and open the project
5. Add an instance of the C++ actor to the startup level
6. Package in windows shipping configuration
7. Run the resulting executable --> crash
Unavailable as the repro was in a shipping build.
There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-297173 in the post.
0 |
Component | UE - CoreTech |
---|---|
Affects Versions | 5.5, 5.6, 5.7 |
Target Fix | 5.7 |
Created | Jun 19, 2025 |
---|---|
Updated | Jul 18, 2025 |