[Menus]: Fix crashes while parsing (#607)
This commit is contained in:
parent
95a220d162
commit
a447a2945a
@ -12,7 +12,7 @@ namespace Assets
|
||||
if (menus.empty()) return;
|
||||
|
||||
// Allocate new menu list
|
||||
Game::MenuList* newList = allocator->allocate<Game::MenuList>();
|
||||
auto* newList = allocator->allocate<Game::MenuList>();
|
||||
if (!newList) return;
|
||||
|
||||
newList->menus = allocator->allocateArray<Game::menuDef_t*>(menus.size());
|
||||
@ -35,7 +35,7 @@ namespace Assets
|
||||
}
|
||||
void IMenuList::mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
||||
{
|
||||
Game::MenuList *asset = header.menuList;
|
||||
auto* asset = header.menuList;
|
||||
|
||||
for (int i = 0; i < asset->menuCount; ++i)
|
||||
{
|
||||
@ -51,7 +51,7 @@ namespace Assets
|
||||
|
||||
Utils::Stream* buffer = builder->getBuffer();
|
||||
Game::MenuList* asset = header.menuList;
|
||||
Game::MenuList* dest = buffer->dest<Game::MenuList>();
|
||||
auto* dest = buffer->dest<Game::MenuList>();
|
||||
|
||||
buffer->save(asset);
|
||||
|
||||
@ -67,7 +67,7 @@ namespace Assets
|
||||
{
|
||||
buffer->align(Utils::Stream::ALIGN_4);
|
||||
|
||||
Game::menuDef_t **destMenus = buffer->dest<Game::menuDef_t*>();
|
||||
auto** destMenus = buffer->dest<Game::menuDef_t*>();
|
||||
buffer->saveArray(asset->menus, asset->menuCount);
|
||||
|
||||
for (int i = 0; i < asset->menuCount; ++i)
|
||||
|
@ -11,7 +11,7 @@ namespace Assets
|
||||
// load from disk
|
||||
auto menus = Components::Menus::LoadMenu(Utils::String::VA("ui_mp/%s.menu", name.data()));
|
||||
|
||||
if (menus.size() == 0) return;
|
||||
if (menus.empty()) return;
|
||||
if (menus.size() > 1) Components::Logger::Print("Menu '{}' on disk has more than one menudef in it. Only saving the first one\n", name);
|
||||
|
||||
header->menu = menus[0].second;
|
||||
|
@ -166,6 +166,13 @@ namespace Components
|
||||
}
|
||||
}
|
||||
|
||||
if (!menu->window.name)
|
||||
{
|
||||
allocator->free(menu->items);
|
||||
allocator->free(menu);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Menus::OverrideMenu(menu);
|
||||
Menus::RemoveMenu(menu->window.name);
|
||||
Menus::MenuList[menu->window.name] = menu;
|
||||
|
@ -265,8 +265,10 @@ namespace Components
|
||||
|
||||
if (asset->type != type) continue;
|
||||
|
||||
const char* assetName = Game::DB_GetXAssetName(asset);
|
||||
if (assetName[0] == ',') ++assetName;
|
||||
const auto* assetName = Game::DB_GetXAssetName(asset);
|
||||
if (!assetName) return -1;
|
||||
if (assetName[0] == ',' && assetName[1] != '\0') ++assetName;
|
||||
else return -1;
|
||||
|
||||
if (this->getAssetName(type, assetName) == name)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user