From be2ebebfda7d04ad1e40bf329271a7b17f501bd1 Mon Sep 17 00:00:00 2001 From: Hyper <34012267+hyperbx@users.noreply.github.com> Date: Mon, 25 Nov 2024 04:37:12 +0000 Subject: [PATCH] guest_stack_var: allow creation without constructing underlying type --- UnleashedRecomp/cpu/guest_stack_var.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/UnleashedRecomp/cpu/guest_stack_var.h b/UnleashedRecomp/cpu/guest_stack_var.h index 541e3651..e4e9406d 100644 --- a/UnleashedRecomp/cpu/guest_stack_var.h +++ b/UnleashedRecomp/cpu/guest_stack_var.h @@ -6,7 +6,7 @@ // DO NOT use this type as anything other than a local variable. // This includes returning. It'll cause memory to leak in the guest stack! -template +template class guest_stack_var { private: @@ -36,19 +36,25 @@ public: guest_stack_var(Args&&... args) { AllocGuestStackMemory(); - new (get()) T(std::forward(args)...); + + if (Init) + new (get()) T(std::forward(args)...); } guest_stack_var(const guest_stack_var& other) { AllocGuestStackMemory(); - new (get()) T(*other->get()); + + if (Init) + new (get()) T(*other->get()); } guest_stack_var(guest_stack_var&& other) { AllocGuestStackMemory(); - new (get()) T(std::move(*other->get())); + + if (Init) + new (get()) T(std::move(*other->get())); } ~guest_stack_var()