]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Improve LBMManager::applyLBMs() code
authorsfan5 <sfan5@live.de>
Sun, 5 Jun 2022 14:58:48 +0000 (16:58 +0200)
committersfan5 <sfan5@live.de>
Sun, 5 Jun 2022 15:48:51 +0000 (17:48 +0200)
Fixes a possible bug for lbms on content ID zero and removes unsafe casts.

src/serverenvironment.cpp

index 06bfc7b98bd7021b940ac092ad3fb8fba83c95c2..39cd7aa642f7d8427dd3f70e6c51915686048fc6 100644 (file)
@@ -258,23 +258,22 @@ void LBMManager::applyLBMs(ServerEnvironment *env, MapBlock *block, u32 stamp)
        v3s16 pos;
        MapNode n;
        content_t c;
-       lbm_lookup_map::const_iterator it = getLBMsIntroducedAfter(stamp);
+       auto it = getLBMsIntroducedAfter(stamp);
        for (; it != m_lbm_lookup.end(); ++it) {
                // Cache previous version to speedup lookup which has a very high performance
                // penalty on each call
-               content_t previous_c{};
-               std::vector<LoadingBlockModifierDef *> *lbm_list = nullptr;
+               content_t previous_c = CONTENT_IGNORE;
+               const std::vector<LoadingBlockModifierDef *> *lbm_list = nullptr;
 
                for (pos.X = 0; pos.X < MAP_BLOCKSIZE; pos.X++)
                        for (pos.Y = 0; pos.Y < MAP_BLOCKSIZE; pos.Y++)
                                for (pos.Z = 0; pos.Z < MAP_BLOCKSIZE; pos.Z++) {
-                                       n = block->getNodeNoEx(pos);
+                                       n = block->getNodeNoCheck(pos, nullptr);
                                        c = n.getContent();
 
                                        // If content_t are not matching perform an LBM lookup
                                        if (previous_c != c) {
-                                               lbm_list = (std::vector<LoadingBlockModifierDef *> *)
-                                                       it->second.lookup(c);
+                                               lbm_list = it->second.lookup(c);
                                                previous_c = c;
                                        }