mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-04-10 03:18:55 +02:00
[android] fix crash due to ctor/dtor ordering for std::random_device being uninitialized when used in other static ctor/dtors (#3806)
wow that's fucking horrible Signed-off-by: lizzie <lizzie@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3806 Reviewed-by: MaranBr <maranbr@eden-emu.dev> Reviewed-by: CamilleLaVey <camillelavey99@gmail.com> Co-authored-by: lizzie <lizzie@eden-emu.dev> Co-committed-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
parent
b4a485e244
commit
21f9db1c27
1 changed files with 8 additions and 5 deletions
|
|
@ -1,19 +1,22 @@
|
||||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include "common/random.h"
|
#include "common/random.h"
|
||||||
|
|
||||||
static std::random_device g_random_device;
|
|
||||||
|
|
||||||
namespace Common::Random {
|
namespace Common::Random {
|
||||||
|
[[nodiscard]] static std::random_device& GetGlobalRandomDevice() noexcept {
|
||||||
|
static std::random_device g_random_device{};
|
||||||
|
return g_random_device;
|
||||||
|
}
|
||||||
[[nodiscard]] u32 Random32(u32 seed) noexcept {
|
[[nodiscard]] u32 Random32(u32 seed) noexcept {
|
||||||
return g_random_device();
|
return GetGlobalRandomDevice()();
|
||||||
}
|
}
|
||||||
[[nodiscard]] u64 Random64(u64 seed) noexcept {
|
[[nodiscard]] u64 Random64(u64 seed) noexcept {
|
||||||
return g_random_device();
|
return GetGlobalRandomDevice()();
|
||||||
}
|
}
|
||||||
[[nodiscard]] std::mt19937 GetMT19937() noexcept {
|
[[nodiscard]] std::mt19937 GetMT19937() noexcept {
|
||||||
return std::mt19937(g_random_device());
|
return std::mt19937(GetGlobalRandomDevice()());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue