Skip to content

Commit

Permalink
2.0 backports
Browse files Browse the repository at this point in the history
  • Loading branch information
landelare committed Aug 14, 2024
1 parent a898cd6 commit 9d88def
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 6 deletions.
6 changes: 5 additions & 1 deletion Plugins/UE5Coro/Source/UE5Coro/Private/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ using namespace UE5Coro::Private;
void FGeneratorPromise::unhandled_exception()
{
#if PLATFORM_EXCEPTIONS_DISABLED
check(!"Exceptions are not supported");
// Hitting this can be a result of the generator itself invoking undefined
// behavior, e.g., by using a bad pointer.
// On Windows, SEH exceptions can end up here if C++ exceptions are disabled.
// If this hinders debugging, feel free to remove it!
checkSlow(!"Unhandled exception from generator!");
#else
throw;
#endif
Expand Down
6 changes: 5 additions & 1 deletion Plugins/UE5Coro/Source/UE5Coro/Private/Promise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ void FPromise::AddContinuation(std::function<void(void*)> Fn)
void FPromise::unhandled_exception()
{
#if PLATFORM_EXCEPTIONS_DISABLED
check(!"Exceptions are not supported");
// Hitting this can be a result of the coroutine itself invoking undefined
// behavior, e.g., by using a bad pointer.
// On Windows, SEH exceptions can end up here if C++ exceptions are disabled.
// If this hinders debugging, feel free to remove it!
checkSlow(!"Unhandled exception from coroutine!");
#else
bUnhandledException = true;
throw;
Expand Down
2 changes: 1 addition & 1 deletion Plugins/UE5Coro/UE5Coro.uplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"FileVersion": 3,
"Version": 1,
"VersionName": "1.10.2",
"VersionName": "1.10.3",
"FriendlyName": "UE5Coro",
"Description": "C++17/20 coroutine implementation for Unreal Engine",
"Category": "Programming",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

using namespace UE5Coro;
using namespace UE5Coro::Private;
using namespace UE5CoroGAS::Private;

namespace
{
Expand All @@ -53,10 +54,30 @@ bool IsTemplate(UObject* Object)
}
}

namespace UE5CoroGAS::Private
{
struct FStrictPredictionKey : FPredictionKey
{
FStrictPredictionKey(const FPredictionKey& Key) noexcept
: FPredictionKey(Key) { }

bool operator==(const FStrictPredictionKey& Other) const noexcept
{
return FPredictionKey::operator==(Other) && Base == Other.Base;
}
};

int32 GetTypeHash(const FStrictPredictionKey& Key) noexcept // ADL
{
return GetTypeHash(static_cast<const FPredictionKey&>(Key)) ^
Key.Base << 16;
}
}

UUE5CoroGameplayAbility::UUE5CoroGameplayAbility()
{
if (::IsTemplate(this))
Activations = new TMap<FPredictionKey, TAbilityPromise<ThisClass>*>;
Activations = new TMap<FStrictPredictionKey, TAbilityPromise<ThisClass>*>;
else
Activations = GetDefault<ThisClass>(GetClass())->Activations;
checkf(Activations, TEXT("Internal error: non-template object before CDO"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include "UE5CoroGAS/AbilityPromises.h"
#include "UE5CoroGameplayAbility.generated.h"

namespace UE5CoroGAS::Private { struct FStrictPredictionKey; }

/**
* Usage summary:
* - Override ExecuteAbility instead of ActivateAbility
Expand All @@ -52,7 +54,8 @@ class UE5COROGAS_API UUE5CoroGameplayAbility : public UGameplayAbility

// One shared per class to support every instancing policy including derived
// classes changing their minds at runtime. The real one is on the CDO.
TMap<FPredictionKey, UE5Coro::Private::TAbilityPromise<ThisClass>*>* Activations;
TMap<UE5CoroGAS::Private::FStrictPredictionKey,
UE5Coro::Private::TAbilityPromise<ThisClass>*>* Activations;

public:
UUE5CoroGameplayAbility();
Expand Down
2 changes: 1 addition & 1 deletion Plugins/UE5CoroGAS/UE5CoroGAS.uplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"FileVersion": 3,
"Version": 1,
"VersionName": "1.10.1",
"VersionName": "1.10.3",
"FriendlyName": "UE5Coro – Gameplay Ability System",
"Description": "C++17/20 coroutines for GAS",
"Category": "Programming",
Expand Down

0 comments on commit 9d88def

Please sign in to comment.