1
0
forked from 0ad/0ad

Avoid calling random for phenotype to avoid OOS

Using the same random generator as for the simulation for previewing
leads to out-of-sync of the random generator with other clients.

This is a quick fix, in the long run one might want to provide an other
random generator for non simulation tasks.

The patch by elexis was attached by Vladislav to issue #6888

Patch-by: elexis
Closes: #6888
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
This commit is contained in:
Ralph Sennhauser 2024-09-23 07:08:54 +02:00
parent 9c72741e69
commit fe78ee12a5
Signed by: sera
SSH Key Fingerprint: SHA256:peL4nxsVEHY8tOsBHev85LILY2TqpfHeutw4LUbOFPQ
2 changed files with 11 additions and 2 deletions

View File

@ -92,7 +92,12 @@ Identity.prototype.Init = function()
this.classesList = GetIdentityClasses(this.template);
this.visibleClassesList = GetVisibleIdentityClasses(this.template);
if (this.template.Phenotype)
this.phenotype = pickRandom(this.GetPossiblePhenotypes());
{
const phenotypes = this.GetPossiblePhenotypes();
// Avoid calling Math.random to avoid out of sync RNG caused by preview entities
this.phenotype = phenotypes[this.entity % phenotypes.length];
}
else
this.phenotype = "default";

View File

@ -2,7 +2,11 @@
<Entity filtered="">
<!-- We only want to include components which are necessary (for the visual previewing of an entity)
and safe (i.e. won't do anything that affects the synchronised simulation state), so additions
to this list should be carefully considered -->
to this list should be carefully considered.
Any Init function of any component listed here may not call Math.random, otherwise the RNG state
would become out of sync with the RNG state of the other clients.
-->
<!-- Attack is needed for the Actor Viewer and attack range overlay -->
<Attack merge=""/>
<BuildRestrictions merge=""/>