I'm catching up with latest episodes and want to point to couple of issues with asset code.
If somebody will remove hha file during iteration in Win32OpenNextFile function (or FindNextFileA will fail there), then for next file Win32OpenNextFile function will return NULL. But code that uses result of this function doesn't expect that and everything will crash when dereferencing NULL pointer in here:
| #define PlatformNoFileErrors(Handle) ((Handle)->NoErrors)
|
Code in LoadAssetWork work queue function has race condition. Because multiple threads will be using same data passed to it (platform_file_handle) the errors won't be processed correctly. If ReadDataFromFile function fails (by setting NoError to false) then next call to PlatformNoFileErrors function potentially won't see error and will process error status from the result of different call to ReadDataFromFile function.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 | internal PLATFORM_WORK_QUEUE_CALLBACK(LoadAssetWork)
{
load_asset_work *Work = (load_asset_work *)Data;
Platform.ReadDataFromFile(Work->Handle, Work->Offset, Work->Size, Work->Destination);
CompletePreviousWritesBeforeFutureWrites;
// TODO(casey): Should we actually fill in bogus data here and set to final state anyway?
if(PlatformNoFileErrors(Work->Handle)) // <====== This depends on result of ReadDataFromFile call above
{
Work->Slot->State = Work->FinalState;
}
EndTaskWithMemory(Work->Task);
|
That's why stdio file API read function returns result instead of storing it somewhere :)