Skip to content

Commit

Permalink
Make GWorld checks stricter
Browse files Browse the repository at this point in the history
  • Loading branch information
landelare committed Nov 12, 2024
1 parent 883997b commit 092b352
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Source/UE5Coro/Private/LatentAwaiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ void FLatentAwaiter::Suspend(FAsyncPromise& Promise)
{
checkf(IsInGameThread(),
TEXT("Latent awaiters may only be used on the game thread"));
checkf(GWorld,
TEXT("Awaiting this can only be done in the context of a world"));
checkf(::IsValid(GWorld),
TEXT("Awaiting this can only be done in the context of a valid world"));

// Prepare a latent action on the subsystem and transfer ownership to that
auto* Sys = GWorld->GetSubsystem<UUE5CoroSubsystem>();
Expand Down
7 changes: 4 additions & 3 deletions Source/UE5Coro/Private/LatentAwaiters_Wait.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ bool WaitUntilTime(void* State, bool bCleanup)
return false;

auto& TargetTime = reinterpret_cast<double&>(State);
checkf(GWorld, TEXT("Internal error: latent poll outside of a world"));
checkf(IsValid(GWorld),
TEXT("Internal error: latent poll outside of a valid world"));
return (GWorld->*GetTime)() >= TargetTime;
}

Expand All @@ -79,8 +80,8 @@ FLatentAwaiter GenericUntil(double Time)
#endif
checkf(IsInGameThread(),
TEXT("Latent awaiters may only be used on the game thread"));
checkf(GWorld,
TEXT("This function may only be used in the context of a world"));
checkf(IsValid(GWorld),
TEXT("This function may only be used in the context of a valid world"));

if constexpr (bTimeIsOffset)
Time += (GWorld->*GetTime)();
Expand Down
2 changes: 1 addition & 1 deletion Source/UE5Coro/Private/LatentChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ using namespace UE5Coro::Private;

std::tuple<FLatentActionInfo, FTwoLives*> Private::MakeLatentInfo()
{
checkf(GWorld, TEXT("Internal error: unguarded world access"));
checkf(IsValid(GWorld), TEXT("Internal error: unguarded world access"));
auto* Sys = GWorld->GetSubsystem<UUE5CoroSubsystem>();
// Will be Released by the FLatentAwaiter from the caller
// and UUE5CoroSubsystem on the latent action's completion.
Expand Down
7 changes: 4 additions & 3 deletions Source/UE5Coro/Public/UE5Coro/LatentChain.inl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ struct FLatentChain<true, bInfo, Type, Types...>
{
static void Call(auto&& Fn, FLatentActionInfo LatentInfo, auto&&... Args)
{
checkf(GWorld, TEXT("Could not chain latent action: no world found"));
checkf(IsValid(GWorld),
TEXT("Could not chain latent action: no valid world found"));
FLatentChain<false, bInfo, Types...>::Call(
std::bind_front(std::forward<decltype(Fn)>(Fn), &*GWorld),
std::move(LatentInfo),
Expand Down Expand Up @@ -165,8 +166,8 @@ Private::FLatentChainAwaiter ChainEx(auto&& Function, auto&&... Args)
checkf(IsInGameThread(),
TEXT("Latent awaiters may only be used on the game thread"));
if constexpr ((... || (std::is_placeholder_v<std::decay_t<decltype(Args)>> == 1)))
checkf(GWorld,
TEXT("Could not chain latent action: no world found for _1"));
checkf(IsValid(GWorld),
TEXT("Could not chain latent action: no valid world found for _1"));
static_assert((... || (std::is_placeholder_v<std::decay_t<decltype(Args)>> == 2)),
"The _2 parameter for LatentInfo is mandatory");

Expand Down
4 changes: 2 additions & 2 deletions UE5Coro.uplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"FileVersion": 3,
"Version": 1,
"VersionName": "2.0",
"VersionName": "2.0.1-RC",
"FriendlyName": "UE5Coro",
"Description": "C++20 coroutine implementation for Unreal Engine",
"Category": "Programming",
Expand All @@ -13,7 +13,7 @@
"EnabledByDefault": true,
"CanContainContent": false,
"CanContainVerse": false,
"IsBetaVersion": false,
"IsBetaVersion": true,
"IsExperimentalVersion": false,
"Installed": false,
"Modules": [
Expand Down

0 comments on commit 092b352

Please sign in to comment.