changes for protection

This commit is contained in:
Nikola Petrov 2025-01-05 00:43:03 +01:00
parent 2439a986a3
commit 9d224968d2

View File

@ -144,7 +144,7 @@ void DnaManager::like(Unit unit)
showed++; showed++;
if (showed == NUM_PER_GEN && queued == NUM_PER_GEN) if (showed >= NUM_PER_GEN && queued >= NUM_PER_GEN) // if buffer was biger in the past showed could be more then NUM_PER_GEN so its changed to >= insted of ==
{ {
newGen(); newGen();
queued = 0; queued = 0;
@ -184,6 +184,9 @@ void DnaManager::newGen()
{ {
for (auto &&i : disliked) for (auto &&i : disliked)
{ {
if (i >= NUM_PER_GEN) // out of bounds error prevention if buffer was in the past biiger then its now
continue;
size_t p1 = mrand::getValue(0, liked.size() - 1, &randSeed); size_t p1 = mrand::getValue(0, liked.size() - 1, &randSeed);
size_t p2 = mrand::getValue(0, liked.size() - 1, &randSeed); size_t p2 = mrand::getValue(0, liked.size() - 1, &randSeed);
while (p1 == p2) while (p1 == p2)
@ -191,6 +194,9 @@ void DnaManager::newGen()
p2 = mrand::getValue(0, liked.size(), &randSeed); p2 = mrand::getValue(0, liked.size(), &randSeed);
} }
if (p1 >= NUM_PER_GEN || p2 >= NUM_PER_GEN) // out of bounds error prevention if buffer was in the past biiger then its now
continue;
p1 = liked[p1]; p1 = liked[p1];
p2 = liked[p2]; p2 = liked[p2];
Dna *p1p = &vector[p1]; Dna *p1p = &vector[p1];