Browse Source

Fix pointer alignment of default random generator object.

Sasha Szpakowski 1 year ago
parent
commit
476e520969
2 changed files with 7 additions and 4 deletions
  1. 3 2
      src/modules/math/MathModule.cpp
  2. 4 2
      src/modules/math/MathModule.h

+ 3 - 2
src/modules/math/MathModule.cpp

@@ -201,11 +201,12 @@ float linearToGamma(float c)
 
 
 Math::Math()
 Math::Math()
 	: Module(M_MATH, "love.math")
 	: Module(M_MATH, "love.math")
-	, rng()
 {
 {
 	RandomGenerator::Seed seed;
 	RandomGenerator::Seed seed;
 	seed.b64 = (uint64) time(nullptr);
 	seed.b64 = (uint64) time(nullptr);
-	rng.setSeed(seed);
+
+	rng.set(new RandomGenerator(), Acquire::NORETAIN);
+	rng->setSeed(seed);
 }
 }
 
 
 Math::~Math()
 Math::~Math()

+ 4 - 2
src/modules/math/MathModule.h

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