From a947de5dd27a5a84bd5b0d502d41d4e217a1de04 Mon Sep 17 00:00:00 2001
From: Rob Swindell <rob@synchro.net>
Date: Thu, 28 Apr 2022 12:59:39 -0700
Subject: [PATCH] Mutex-protect the ring buffers (as we do in the *nix builds)

This fixes an observed crash in sexyz for Windows. The crash was in RingBufWrite() where 'remain' was set to -1 (4.2B) apparently because pHead and/or pTail changed (to pTail=pHead) during the invocation of the RINGBUF_FILL_LEVEL() macro, because it wasn't thread-safe.

Amazing this problem never came up before.
---
 src/sbbs3/sexyz.vcxproj | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/sbbs3/sexyz.vcxproj b/src/sbbs3/sexyz.vcxproj
index 68a0a5161f..ac87592430 100644
--- a/src/sbbs3/sexyz.vcxproj
+++ b/src/sbbs3/sexyz.vcxproj
@@ -66,7 +66,7 @@
     <ClCompile>
       <Optimization>Disabled</Optimization>
       <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>_DEBUG;WIN32;_CONSOLE;SBBS_EXPORTS;RINGBUF_SEM;RINGBUF_EVENT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PreprocessorDefinitions>_DEBUG;WIN32;_CONSOLE;SBBS_EXPORTS;RINGBUF_SEM;RINGBUF_EVENT;RINGBUF_MUTEX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
       <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
       <PrecompiledHeaderOutputFile>.\msvc.win32.debug\sexyz/sexyz.pch</PrecompiledHeaderOutputFile>
@@ -110,7 +110,7 @@
       <Optimization>MaxSpeed</Optimization>
       <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
       <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>NDEBUG;WIN32;_CONSOLE;SBBS_EXPORTS;RINGBUF_SEM;RINGBUF_EVENT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PreprocessorDefinitions>NDEBUG;WIN32;_CONSOLE;SBBS_EXPORTS;RINGBUF_SEM;RINGBUF_EVENT;RINGBUF_MUTEX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <StringPooling>true</StringPooling>
       <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
       <FunctionLevelLinking>true</FunctionLevelLinking>
-- 
GitLab