From 7dbb258a4794e1421f29c2cea318f1c9b6234cc1 Mon Sep 17 00:00:00 2001 From: rackover Date: Fri, 9 Apr 2021 18:17:23 +0200 Subject: [PATCH] Correct array allocation for loaded sounds --- .../AssetInterfaces/Isnd_alias_list_t.cpp | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/Components/Modules/AssetInterfaces/Isnd_alias_list_t.cpp b/src/Components/Modules/AssetInterfaces/Isnd_alias_list_t.cpp index 881355b4..bacaf8c2 100644 --- a/src/Components/Modules/AssetInterfaces/Isnd_alias_list_t.cpp +++ b/src/Components/Modules/AssetInterfaces/Isnd_alias_list_t.cpp @@ -25,6 +25,15 @@ namespace Assets auto aliases = aliasesContainer.array_items(); aliasList->count = aliases.size(); + + // Allocate + aliasList->head = builder->getAllocator()->allocateArray(aliasList->count); + if (!aliasList->head) + { + Components::Logger::Print("Error allocating memory for sound alias structure!\n"); + return; + } + aliasList->aliasName = builder->getAllocator()->duplicateString(infoData["aliasName"].string_value().c_str()); for (size_t i = 0; i < aliasList->count; i++) @@ -37,14 +46,6 @@ namespace Assets return; } - // Allocate - aliasList->head = builder->getAllocator()->allocate(); - if (!aliasList->head) - { - Components::Logger::Print("Error allocating memory for sound alias structure!\n"); - return; - } - aliasList->head->soundFile = builder->getAllocator()->allocate(); if (!aliasList->head->soundFile) { @@ -281,21 +282,29 @@ namespace Assets if (volumeFalloffCurve.is_string()) { - alias->volumeFalloffCurve = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_SOUND_CURVE, volumeFalloffCurve.string_value(), builder).sndCurve; + alias->volumeFalloffCurve = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_SOUND_CURVE, "$default" /*volumeFalloffCurve.string_value().c_str()*/, builder).sndCurve; } - if (type.number_value() == 1) // Loaded + if (type.number_value() == Game::snd_alias_type_t::SAT_LOADED) // Loaded { alias->soundFile->type = Game::SAT_LOADED; - alias->soundFile->u.loadSnd = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_LOADED_SOUND, soundFile.string_value(), builder).loadSnd; + alias->soundFile->u.loadSnd = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_LOADED_SOUND, soundFile.string_value().c_str(), builder).loadSnd; } - else if (type.number_value() == 2) // Streamed + else if (type.number_value() == Game::snd_alias_type_t::SAT_STREAMED) // Streamed { alias->soundFile->type = Game::SAT_STREAMED; std::string streamedFile = soundFile.string_value(); + std::string directory = ""s; int split = streamedFile.find_last_of('/'); - alias->soundFile->u.streamSnd.filename.info.raw.dir = builder->getAllocator()->duplicateString(streamedFile.substr(0, split).c_str()); - alias->soundFile->u.streamSnd.filename.info.raw.name = builder->getAllocator()->duplicateString(streamedFile.substr(split).c_str()); + + if (split >= 0) + { + directory = streamedFile.substr(split); + streamedFile = streamedFile.substr(0, split); + } + + alias->soundFile->u.streamSnd.filename.info.raw.dir = builder->getAllocator()->duplicateString(directory.c_str()); + alias->soundFile->u.streamSnd.filename.info.raw.name = builder->getAllocator()->duplicateString(streamedFile.c_str()); } else { @@ -303,10 +312,7 @@ namespace Assets return; } - if (i == 0) - { - aliasList->head = alias; - } + aliasList->head[i] = *alias; } else {