Skip to content

Commit 5bc2994

Browse files
committed
GH-421 Fix 4.3 stack allocation crash issues with RefCounted
1 parent d696fd1 commit 5bc2994

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/common/guid.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ String Guid::to_string() const
6666

6767
Guid Guid::create_guid()
6868
{
69-
RandomNumberGenerator rng;
69+
Ref<RandomNumberGenerator> rng(memnew(RandomNumberGenerator));
7070

71-
uint32_t a = rng.randi();
72-
uint32_t b = rng.randi();
73-
uint32_t c = rng.randi();
74-
uint32_t d = rng.randi();
71+
uint32_t a = rng->randi();
72+
uint32_t b = rng->randi();
73+
uint32_t c = rng->randi();
74+
uint32_t d = rng->randi();
7575

7676
// The 4 bits of digit M indicate the GUID version, and the 1-3 most significant bits
7777
// of digit N indicate the UUID variant.

src/script/nodes/flow_control/chance.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@
1919
class OScriptNodeChanceInstance : public OScriptNodeInstance
2020
{
2121
DECLARE_SCRIPT_NODE_INSTANCE(OScriptNodeChance);
22-
RandomNumberGenerator _random;
22+
Ref<RandomNumberGenerator> _random;
2323
int _chance{ 0 };
2424

2525
public:
2626
int step(OScriptExecutionContext& p_context) override
2727
{
28-
const int _calculated_chance = _random.randi_range(0, 100);
28+
if (!_random.is_valid())
29+
_random.instantiate();
30+
31+
const int _calculated_chance = _random->randi_range(0, 100);
2932
return _calculated_chance <= _chance ? 0 : 1;
3033
}
3134
};

src/script/nodes/flow_control/random.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class OScriptNodeRandomInstance : public OScriptNodeInstance
2020
{
2121
DECLARE_SCRIPT_NODE_INSTANCE(OScriptNodeRandom);
2222

23-
RandomNumberGenerator _random;
23+
Ref<RandomNumberGenerator> _random;
2424
int _possibilities{ 0 };
2525

2626
public:
@@ -29,7 +29,10 @@ class OScriptNodeRandomInstance : public OScriptNodeInstance
2929
if (_possibilities == 0)
3030
return -1;
3131

32-
return _random.randi_range(0, _possibilities - 1);
32+
if (!_random.is_valid())
33+
_random.instantiate();
34+
35+
return _random->randi_range(0, _possibilities - 1);
3336
}
3437
};
3538

0 commit comments

Comments
 (0)