<div class="markdown_content"><p>I've discovered that the file locking done on Windows doesn't actually prevent Game from seeing a file in the middle of being written. If a file is opened ACCESS WRITE (aka ACCESS_WRITE), whether using the locking I implemented in OPENFILE, or FB's builtin locking if OPEN is used with LOCK, the file is first opened for write, which truncates it to length zero, and <em>then</em> is locked. And it turns out it's actually really common to hit the file at that exact moment if both Game and Custom are opening it often.</p>
<p>I should be able to make OPENFILE work around this problem.</p>
<p>However ACCESS WRITE is only used in 16 places, and shop and item data aren't among them.</p>
<hr/>
<p><strong> <a class="alink" href="https://sourceforge.net/p/ohrrpgce/bugs/2035/">[bugs:#2035]</a> Missing/corrupt data in-game while using Test Game</strong></p>
<p><strong>Status:</strong> open<br/>
<strong>Milestone:</strong> OHRRPGCE<br/>
<strong>Labels:</strong> test game shops <br/>
<strong>Created:</strong> Tue Aug 28, 2018 09:06 AM UTC by TeeEmCee<br/>
<strong>Last Updated:</strong> Tue Aug 28, 2018 10:27 AM UTC<br/>
<strong>Owner:</strong> nobody</p>
<p>Wobbler reported once:</p>
<blockquote>
<p>...while testing my game, I went into a shop to sell some items and every option was blank. It still showed the correct sell price and I could sell stuff, but I couldn't see any of the item names. I closed the game, opened it again, and everything was back to normal</p>
</blockquote>
<p>SwordPlay also said he'd seen something like it, but couldn't remember anything at all.</p>
<p>While Custom is writing a lump it locks it to ensure that Game doesn't simultaneously try to read it. However, our load/save code often opens and closes a file multiple times, or writes multiple files, and there's no synchronisation around such operations to prevent Game from seeing inconsistent state. So I think there are a lots of weird things you might see if you get very unlucky.</p>
<p>In the case of item names note we don't cache those, and instead open .ITM to read the name of each item in a shop. But the names of the things in a shop are taken from STF, not ITM. The real item names are used on the right-hand-side info pane. The STF records for a shop are read/written all at once, so I don't know how what Wobbler saw could happen.</p>
<p>This bug report isn't specifically about shops though.</p>
<hr/>
<p>Sent from sourceforge.net because ohrrpgce@lists.motherhamster.org is subscribed to <a href="https://sourceforge.net/p/ohrrpgce/bugs/">https://sourceforge.net/p/ohrrpgce/bugs/</a></p>
<p>To unsubscribe from further messages, a project admin can change settings at <a href="https://sourceforge.net/p/ohrrpgce/admin/bugs/options.">https://sourceforge.net/p/ohrrpgce/admin/bugs/options.</a>  Or, if this is a mailing list, you can unsubscribe from the mailing list.</p></div>