Fix memory leak when CSM blocks inventory opening (#34)

master
Vitaliy 2022-02-04 16:27:13 +03:00 committed by GitHub
parent 2d406b8318
commit eda0178885
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 10 deletions

View File

@ -2094,20 +2094,19 @@ void Game::openInventory()
infostream << "Game: Launching inventory" << std::endl;
PlayerInventoryFormSource *fs_src = new PlayerInventoryFormSource(client);
InventoryLocation inventoryloc;
inventoryloc.setCurrentPlayer();
if (!client->modsLoaded()
|| !client->getScript()->on_inventory_open(fs_src->m_client->getInventory(inventoryloc))) {
TextDest *txt_dst = new TextDestPlayerInventory(client);
auto *&formspec = m_game_ui->updateFormspec("");
GUIFormSpecMenu::create(formspec, client, &input->joystick, fs_src,
txt_dst, client->getFormspecPrepend(), sound);
if (client->modsLoaded() && client->getScript()->on_inventory_open(client->getInventory(inventoryloc)))
return; // CSM prevented inventory opening
formspec->setFormSpec(fs_src->getForm(), inventoryloc);
}
PlayerInventoryFormSource *fs_src = new PlayerInventoryFormSource(client);
TextDest *txt_dst = new TextDestPlayerInventory(client);
auto *&formspec = m_game_ui->updateFormspec("");
GUIFormSpecMenu::create(formspec, client, &input->joystick, fs_src,
txt_dst, client->getFormspecPrepend(), sound);
formspec->setFormSpec(fs_src->getForm(), inventoryloc);
}