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 @@ class Math : public Module RandomGenerator *getRandomGenerator() { - return &rng; + return rng.get(); } /** @@ -120,7 +120,9 @@ class Math : public Module private: - RandomGenerator rng; + // All love objects accessible in Lua should be heap-allocated, + // to guarantee a minimum pointer alignment. + StrongRef rng; }; // Math