Skip to content

Fix input buffer crash #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ void UGBFAbilityInputBufferComponent::BindActions()
return;
}

for ( auto & input_config : hero_component->GetBoundActionsByInputconfig() )
auto & actions_per_input_config = hero_component->GetBoundActionsByInputconfig();

for ( auto & [ input_config, actions ] : actions_per_input_config )
{
for ( auto & tag : InputTagsToCheck )
{
if ( const auto * input_action = input_config.Key->FindAbilityInputActionForTag( tag ) )
if ( const auto * input_action = input_config->FindAbilityInputActionForTag( tag ) )
{
BindHandles.Add( input_component->BindAction( input_action, ETriggerEvent::Triggered, this, &ThisClass::AbilityInputTagPressed, tag ).GetHandle() );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void UGBFHeroComponent::AddAdditionalInputConfig( const UGBFInputConfig * input_
if ( ensureAlways( BoundActionsByInputConfig.Find( input_config ) == nullptr ) )
{
auto & bind_handles = BoundActionsByInputConfig.Add( input_config );
input_component->BindAbilityActions( input_config, this, &ThisClass::Input_AbilityInputTagPressed, &ThisClass::Input_AbilityInputTagReleased, /*out*/ bind_handles );
input_component->BindAbilityActions( input_config, this, &ThisClass::Input_AbilityInputTagPressed, &ThisClass::Input_AbilityInputTagReleased, /*out*/ bind_handles.Handles );
}
}
}
Expand All @@ -196,7 +196,7 @@ void UGBFHeroComponent::RemoveAdditionalInputConfig( const UGBFInputConfig * inp

if ( auto * bind_handles = BoundActionsByInputConfig.Find( input_config ) )
{
input_component->RemoveBinds( *bind_handles );
input_component->RemoveBinds( bind_handles->Handles );
BoundActionsByInputConfig.Remove( input_config );
}
}
Expand Down Expand Up @@ -224,7 +224,7 @@ void UGBFHeroComponent::ClearAbilityCameraMode( const FGameplayAbilitySpecHandle
}
}

const TMap< const UGBFInputConfig *, TArray< uint32 > > & UGBFHeroComponent::GetBoundActionsByInputconfig() const
const TMap< const UGBFInputConfig *, FGBFBoundInputHandles > & UGBFHeroComponent::GetBoundActionsByInputconfig() const
{
return BoundActionsByInputConfig;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ class UGBFInputComponent;
class UGBFInputConfig;
class UGBFCameraMode;

USTRUCT()
struct FGBFBoundInputHandles
{
GENERATED_BODY()

public:
UPROPERTY()
TArray< uint32 > Handles;
};

UCLASS( abstract )
class GAMEBASEFRAMEWORK_API UGBFHeroComponent : public UGBFPawnComponent
{
Expand Down Expand Up @@ -48,7 +58,7 @@ class GAMEBASEFRAMEWORK_API UGBFHeroComponent : public UGBFPawnComponent
/** Clears the camera override if it is set */
void ClearAbilityCameraMode( const FGameplayAbilitySpecHandle & owning_spec_handle );

const TMap< const UGBFInputConfig *, TArray< uint32 > > & GetBoundActionsByInputconfig() const;
const TMap< const UGBFInputConfig *, FGBFBoundInputHandles > & GetBoundActionsByInputconfig() const;

protected:
void OnRegister() override;
Expand Down Expand Up @@ -82,10 +92,11 @@ class GAMEBASEFRAMEWORK_API UGBFHeroComponent : public UGBFPawnComponent
UPROPERTY()
TSubclassOf< UGBFCameraMode > AbilityCameraMode;

UPROPERTY()
TMap< const UGBFInputConfig *, FGBFBoundInputHandles > BoundActionsByInputConfig;

/** Spec handle for the last ability to set a camera mode. */
FGameplayAbilitySpecHandle AbilityCameraModeOwningSpecHandle;

TMap< const UGBFInputConfig *, TArray< uint32 > > BoundActionsByInputConfig;
};

FORCEINLINE bool UGBFHeroComponent::IsReadyToBindInputs() const
Expand Down
Loading