[chronojump] Fixed NextSound could crash by the other thread



commit 17bbd34e28a6d64cb95a6716b2013cbb21ab9b4e
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Apr 18 22:09:08 2018 +0200

    Fixed NextSound could crash by the other thread

 src/util.cs |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/src/util.cs b/src/util.cs
index 6e8fbbe..c37c7d2 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -1530,9 +1530,19 @@ public class Util
                if(soundList == null)
                        return;
 
-               soundListPos ++;
-               if(soundListPos >= soundList.Count)
+               if(soundListPos +1 >= soundList.Count)
                        soundListPos = 0;
+               else
+                       soundListPos ++;
+
+               /*
+                * done like above instead of below code,
+                * to ensure soundListPos will not be outside the array when the other thread reads
+                *
+                * soundListPos ++;
+                * if(soundListPos >= soundList.Count)
+                *      soundListPos = 0;
+                */
        }
 
        private static string getSoundFromSoundList()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]