Skip to content

Commit

Permalink
Fix pointer alignment of default random generator object.
Browse files Browse the repository at this point in the history
  • Loading branch information
slime73 committed Feb 25, 2024
1 parent 7225955 commit cdba82a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/modules/math/MathModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 4 additions & 2 deletions src/modules/math/MathModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class Math : public Module

RandomGenerator *getRandomGenerator()
{
return &rng;
return rng.get();
}

/**
Expand All @@ -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<RandomGenerator> rng;

}; // Math

Expand Down

0 comments on commit cdba82a

Please sign in to comment.