Changeset - 78ecf5feebe4
[Not reviewed]
default
0 2 0
Jason Maltzen - 9 years ago 2015-12-23 23:52:36
jason@hiddenachievement.com
Fix a crash with potential multi-threaded access to paint recipes.
2 files changed with 17 insertions and 1 deletions:
0 comments (0 inline, 0 general)
PaintRecipe.cs
Show inline comments
...
 
@@ -45,32 +45,47 @@ namespace DesertPaintLab
 
                this.quantity = quantity;
 
            }
 
        };
 

	
 
        private List<RecipeIngredient> recipe = new List<RecipeIngredient>();
 
        private List<string> reagents = new List<string>();
 

	
 
        private bool dirty = false;
 
        private PaintColor reactedColor = new PaintColor();
 
        private PaintColor baseColor = new PaintColor();
 
        private ReactionSet reactions;
 

	
 
        public PaintRecipe()
 
        {
 
        }
 

	
 
        public PaintRecipe(PaintRecipe other)
 
        {
 
            this.dirty = true;
 
            this.reactions = other.reactions;
 
            foreach (string reagentName in other.reagents)
 
            {
 
                this.reagents.Add(reagentName);
 
            }
 
            foreach (RecipeIngredient copyIngredient in other.recipe)
 
            {
 
                RecipeIngredient ingredient = new RecipeIngredient(copyIngredient.name, copyIngredient.quantity);
 
                this.recipe.Add(ingredient);
 
            }
 
        }
 

	
 
        public List<RecipeIngredient> Ingredients
 
        {
 
            get {
 
                return recipe;
 
            }
 
        }
 

	
 
        public ReactionSet Reactions
 
        {
 
            get
 
            {
 
                return reactions;
 
            }
 
            set
 
            {
 
                dirty = true;
RecipeGeneratorWindow.cs
Show inline comments
...
 
@@ -187,59 +187,60 @@ namespace DesertPaintLab
 
                maxIngredientsSpinButton.Sensitive = true;
 
                maxRecipeSpinButton.Sensitive = true;
 
                fullQuantitySpinButton.Sensitive = true;
 
                fullQuantityDepthSpinButton.Sensitive = true;
 
                //generator = null; // don't. Hang on to generator for resume.
 
                profile.SaveRecipes();
 
                if (canceling)
 
                {
 
                    stopResumeButton.Label = "Resume";
 
                    stopResumeButton.Sensitive = true;
 
                }
 
            });
 
        }
 

	
 
        protected void OnNewRecipe(object sender, NewRecipeEventArgs args)
 
        {
 
            PaintRecipe recipe = new PaintRecipe(args.Recipe); // copy it
 
            Gtk.Application.Invoke(delegate
 
            {
 
                progressBar.Pulse();
 
                // TODO: Add item to recipe list only if not already listed
 
                bool exists = false;
 
                Gtk.TreeIter iter;
 
                if (colorStore.GetIterFirst(out iter))
 
                {
 
                    do
 
                    {
 
                        string color = (string)colorStore.GetValue(iter, 0);
 
                        if (color.Equals(args.Color))
 
                        {
 
                            exists = true;
 
                            break;
 
                        }
 
                    } while (colorStore.IterNext(ref iter));
 
                }
 
                if (!exists)
 
                {
 
                    Console.WriteLine("Add new recipe for {0}", args.Color);
 
                    //    bool isMissingReactions = args.Recipe.CheckMissingReactions(ref missingReactions);
 
                    //    string missingReactionLabel = isMissingReactions ? "X" : "";
 
                    colorStore.AppendValues(args.Color); // , missingReactionLabel);
 
                    countLabel.Text = String.Format("{0} / {1}", generator.Recipes.Count, Palette.Count);
 
                }
 
                profile.SetRecipe(args.Recipe);
 
                profile.SetRecipe(recipe);
 
            });
 
        }
 

	
 
        protected void OnProgress(object sender, EventArgs args)
 
        {
 
            Gtk.Application.Invoke(delegate
 
            {
 
                // TODO: based on time rather than count
 
                long progressTime = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
 
                long delta = progressTime - lastProgressUpdate;
 
                if (delta > 30)
 
                {
 
                    progressBar.Pulse();
 
                    lastProgressUpdate = progressTime;
 
                }
 
                delta = progressTime - lastStatusUpdate;
0 comments (0 inline, 0 general)