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
This commit is contained in:
Paramat 2017-05-23 18:54:37 +01:00 committed by Loïc Blot
parent 05309229b8
commit 9ff5302c8b

@ -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,11 +3979,10 @@ 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)) {
if (client->moddingEnabled() &&
client->getScript()->on_dignode(nodepos, wasnode)) {
return;
}
}
client->removeNode(nodepos);
}