From 476e520969a4d0d4c9e514994e73c6cd9d7f8265 Mon Sep 17 00:00:00 2001 From: Sasha Szpakowski Date: Sun, 25 Feb 2024 11:23:52 -0400 Subject: [PATCH] Fix pointer alignment of default random generator object. --- src/modules/math/MathModule.cpp | 5 +++-- src/modules/math/MathModule.h | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/modules/math/MathModule.cpp b/src/modules/math/MathModule.cpp index 42fb70c2a..122c35163 100644 --- a/src/modules/math/MathModule.cpp +++ b/src/modules/math/MathModule.cpp @@ -201,11 +201,12 @@ float linearToGamma(float c) Math::Math() : Module(M_MATH, "love.math") - , rng() { RandomGenerator::Seed seed; seed.b64 = (uint64) time(nullptr); - rng.setSeed(seed); + + rng.set(new RandomGenerator(), Acquire::NORETAIN); + rng->setSeed(seed); } Math::~Math() diff --git a/src/modules/math/MathModule.h b/src/modules/math/MathModule.h index adf0ec0d3..645df8aae 100644 --- a/src/modules/math/MathModule.h +++ b/src/modules/math/MathModule.h @@ -102,7 +102,7 @@ public: RandomGenerator *getRandomGenerator() { - return &rng; + return rng.get(); } /** @@ -120,7 +120,9 @@ public: private: - RandomGenerator rng; + // All love objects accessible in Lua should be heap-allocated, + // to guarantee a minimum pointer alignment. + StrongRef rng; }; // Math