From: Paramat Date: Tue, 23 May 2017 17:54:37 +0000 (+0100) Subject: Client crashfix: load meta after digging (#5801) X-Git-Tag: 0.4.16~67 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=9ff5302c8bf1cc270ca144c9f2cfcb99f6903605;p=oweals%2Fminetest.git Client crashfix: load meta after digging (#5801) Fixes a crash caused in MTGame by breaking and right-clicking a chest. If loading meta, digging, node can disappear and we looked at meta, which is wrong because meta became NULL. Pointer is invalidated and we read wrong memory area --- diff --git a/src/game.cpp b/src/game.cpp index 5d4edb3d0..1ddf07fd1 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -3744,6 +3744,13 @@ void Game::handlePointingAtNode(const PointedThing &pointed, const ItemDefinitio */ ClientMap &map = client->getEnv().getClientMap(); + + if (runData.nodig_delay_timer <= 0.0 && isLeftPressed() + && client->checkPrivilege("interact")) { + handleDigging(pointed, nodepos, playeritem_toolcap, dtime); + } + + // This should be done after digging handling NodeMetadata *meta = map.getNodeMetadata(nodepos); if (meta) { @@ -3757,11 +3764,6 @@ void Game::handlePointingAtNode(const PointedThing &pointed, const ItemDefinitio } } - if (runData.nodig_delay_timer <= 0.0 && isLeftPressed() - && client->checkPrivilege("interact")) { - handleDigging(pointed, nodepos, playeritem_toolcap, dtime); - } - if ((getRightClicked() || runData.repeat_rightclick_timer >= m_repeat_right_click_time) && client->checkPrivilege("interact")) { @@ -3977,10 +3979,9 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos, bool is_valid_position; MapNode wasnode = map.getNodeNoEx(nodepos, &is_valid_position); if (is_valid_position) { - if (client->moddingEnabled()) { - if (client->getScript()->on_dignode(nodepos, wasnode)) { - return; - } + if (client->moddingEnabled() && + client->getScript()->on_dignode(nodepos, wasnode)) { + return; } client->removeNode(nodepos); }