From e9ceead81dd989936e2de3ff7cd7496aecd09d39 Mon Sep 17 00:00:00 2001 From: Jozef Behran Date: Wed, 7 Aug 2019 12:06:45 +0200 Subject: [PATCH] Fix unnecessary exception use in Map::isNodeUnderground The isNodeUnderground calls getBlockNoCreate which calls getBlockNoCreateNoEx and throws InvalidPositionException if the returned value is nullptr, which isNodeUnderground then catches to return "false". Remove the try..catch in isNodeUnderground by calling getBlockNoCreateNoEx instead of getBlockNoCreate and checking the returned value for nullptr. --- src/map.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/map.cpp b/src/map.cpp index 590c3f2f5..a1389fd10 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -152,14 +152,8 @@ MapBlock * Map::getBlockNoCreate(v3s16 p3d) bool Map::isNodeUnderground(v3s16 p) { v3s16 blockpos = getNodeBlockPos(p); - try{ - MapBlock * block = getBlockNoCreate(blockpos); - return block->getIsUnderground(); - } - catch(InvalidPositionException &e) - { - return false; - } + MapBlock *block = getBlockNoCreateNoEx(blockpos); + return block && block->getIsUnderground(); } bool Map::isValidPosition(v3s16 p)