Skip to content

Commit

Permalink
Fix: Stack allocated UObject (#59)
Browse files Browse the repository at this point in the history
* Construct object with pointer instead of ref
* Removed Stack allocated UObject
  • Loading branch information
JBenda authored Oct 17, 2023
1 parent 2f8a08f commit a8d324f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions unreal/inkcpp/Source/inkcpp/Private/InkChoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ FString UInkChoice::GetText() const
return data->text();
}

UInkChoice::UInkChoice() {
tags = NewObject<UTagList>();
}

int UInkChoice::GetIndex() const
{
return data->index();
}

const UTagList* UInkChoice::GetTags() const
{
return &tags;
return tags;
}

void UInkChoice::Initialize(const ink::runtime::choice* c)
Expand All @@ -25,6 +29,6 @@ void UInkChoice::Initialize(const ink::runtime::choice* c)
for(unsigned i = 0; i < c->num_tags(); ++i) {
fstring_tags.Add(FString(c->get_tag(i)));
}
tags.Initialize(fstring_tags);
tags->Initialize(fstring_tags);
}
}
4 changes: 3 additions & 1 deletion unreal/inkcpp/Source/inkcpp/Public/InkChoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class UInkChoice : public UObject
{
GENERATED_BODY()
public:
UInkChoice();

UFUNCTION(BlueprintPure, Category="Ink")
FString GetText() const;

Expand All @@ -29,5 +31,5 @@ class UInkChoice : public UObject

private:
const ink::runtime::choice* data;
UTagList tags;
TObjectPtr<UTagList> tags;
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ DECLARE_LOG_CATEGORY_EXTERN(InkCpp, Log, All);
DEFINE_LOG_CATEGORY(InkCpp);

UInkAssetFactory::UInkAssetFactory(const FObjectInitializer& ObjectInitializer)
: UFactory(ObjectInitializer), FReimportHandler(), object_ptr(*this)
: UFactory(ObjectInitializer), FReimportHandler(), object_ptr(this)
{
// Add ink format
Formats.Add(FString(TEXT("json;")) + NSLOCTEXT("UInkAssetFactory", "FormatInkJSON", "Ink JSON File").ToString());
Expand Down

0 comments on commit a8d324f

Please sign in to comment.