From afb608ef7a4494a517ef13f1b9f17d9c85513ce8 Mon Sep 17 00:00:00 2001 From: profan Date: Fri, 5 Jun 2026 00:14:35 +0100 Subject: [PATCH] ensure evaluation cannot be racey --- Program.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Program.cs b/Program.cs index f4b7b0b..2d16292 100644 --- a/Program.cs +++ b/Program.cs @@ -60,9 +60,9 @@ void Main() currentOutputTexture = Raylib.LoadTextureFromImage(currentOutputImage); } } - + + // options?? bool shouldUseParallelism = true; - bool shouldUseSimd = true; bool isEvaluating = false; bool shouldEvaluate = false; @@ -75,16 +75,21 @@ void Main() Raylib.ClearBackground(Color.White); - if (shouldEvaluate & !isEvaluating) + if (shouldEvaluate && isEvaluating) { - shouldUpdateTexture = true; - currentOutputImageData.AsSpan()[..currentOutputImageData.Length].Clear(); + shouldEvaluate = false; + } + if (shouldEvaluate && !isEvaluating) + { + isEvaluating = true; + shouldUpdateTexture = true; InterpreterOptions interpreterOptions = (shouldUseParallelism ? InterpreterOptions.Parallelism : default); Task.Run(() => { Instruction[] instructions = Parsing.Parse(programsProsperoVm); + currentOutputImageData.AsSpan()[..currentOutputImageData.Length].Clear(); Interpreter.Evaluate(instructions, imageSize: currentOutputImageSize, interpreterOptions, currentOutputImageData); Raylib.UpdateTexture(currentOutputTexture, currentOutputImageData); shouldCancelUpdateTexture = true;