Workaround for memory corruption in asset processor

Somehow the asset processor threads corrupt each others memory - replace
the asset of thread X with the asset of thread Y.
Weird.
This commit is contained in:
Kevin Trogant 2024-02-28 13:57:50 +01:00
parent 9d2987121e
commit 8dc4f794b3

View File

@ -49,7 +49,7 @@ typedef struct {
RT_CVAR_S(rt_AssetDirectory, "Name of the asset directory. Default: assets", "assets"); RT_CVAR_S(rt_AssetDirectory, "Name of the asset directory. Default: assets", "assets");
RT_CVAR_I(rt_AssetDBSize, "Size of the asset database. Default: 1024", 1024); RT_CVAR_I(rt_AssetDBSize, "Size of the asset database. Default: 1024", 1024);
RT_CVAR_I(rt_AssetProcessingThreads, "Number of asset processing threads. Default: 4", 4); RT_CVAR_I(rt_AssetProcessingThreads, "Number of asset processing threads. Default: 4", 1);
RT_CVAR_I(rt_AssetProcessorArenaSize, RT_CVAR_I(rt_AssetProcessorArenaSize,
"Size of the per-thread asset processor arena. Default: 128 MiB", "Size of the per-thread asset processor arena. Default: 128 MiB",
(int)RT_MB(128)); (int)RT_MB(128));
@ -394,9 +394,8 @@ static void ProcessorThreadEntry(void *param) {
} }
RT_DLLEXPORT void rtWaitForAssetProcessing(void) { RT_DLLEXPORT void rtWaitForAssetProcessing(void) {
int turns = 5; int turns = 10;
while (turns > 0) { while (turns > 0) {
rtSleep(100);
int in_processing_count = 0; int in_processing_count = 0;
for (int i = 0; i < rt_AssetDBSize.i; ++i) { for (int i = 0; i < rt_AssetDBSize.i; ++i) {
rtLockRead(&_asset_db.lock); rtLockRead(&_asset_db.lock);
@ -404,8 +403,10 @@ RT_DLLEXPORT void rtWaitForAssetProcessing(void) {
++in_processing_count; ++in_processing_count;
rtUnlockRead(&_asset_db.lock); rtUnlockRead(&_asset_db.lock);
} }
if (!in_processing_count) if (!in_processing_count) {
--turns; --turns;
rtSleep(250);
}
} }
} }