From 955e5257d559d75490e5b2febe4a4d1b6597118e Mon Sep 17 00:00:00 2001 From: MihailRis Date: Fri, 18 Oct 2024 07:56:18 +0300 Subject: [PATCH] fix: conditional jump or move depends on uninitialised value --- src/logic/BlocksController.cpp | 7 ++++--- src/logic/BlocksController.hpp | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/logic/BlocksController.cpp b/src/logic/BlocksController.cpp index 32802780..f8a716d0 100644 --- a/src/logic/BlocksController.cpp +++ b/src/logic/BlocksController.cpp @@ -5,6 +5,7 @@ #include "items/Inventory.hpp" #include "lighting/Lighting.hpp" #include "maths/fastmaths.hpp" +#include "scripting/scripting.hpp" #include "util/timeutil.hpp" #include "voxels/Block.hpp" #include "voxels/Chunk.hpp" @@ -12,7 +13,6 @@ #include "voxels/voxel.hpp" #include "world/Level.hpp" #include "world/World.hpp" -#include "scripting/scripting.hpp" BlocksController::BlocksController(Level* level, uint padding) : level(level), @@ -111,7 +111,7 @@ void BlocksController::randomTick( int bx = random.rand() % CHUNK_W; int by = random.rand() % segheight + s * segheight; int bz = random.rand() % CHUNK_D; - const voxel& vox = chunk.voxels[(by * CHUNK_D + bz) * CHUNK_W + bx]; + const voxel& vox = chunk.voxels[vox_index(bx, by, bz)]; auto& block = indices->blocks.require(vox.id); if (block.rt.funcsset.randupdate) { scripting::random_update_block( @@ -153,7 +153,8 @@ int64_t BlocksController::createBlockInventory(int x, int y, int z) { auto inv = chunk->getBlockInventory(lx, y, lz); if (inv == nullptr) { auto indices = level->content->getIndices(); - auto& def = indices->blocks.require(chunk->voxels[vox_index(lx, y, lz)].id); + auto& def = + indices->blocks.require(chunk->voxels[vox_index(lx, y, lz)].id); int invsize = def.inventorySize; if (invsize == 0) { return 0; diff --git a/src/logic/BlocksController.hpp b/src/logic/BlocksController.hpp index a3baf96f..1754ced3 100644 --- a/src/logic/BlocksController.hpp +++ b/src/logic/BlocksController.hpp @@ -31,7 +31,7 @@ class BlocksController { util::Clock blocksTickClock; util::Clock worldTickClock; uint padding; - FastRandom random; + FastRandom random {}; std::vector blockInteractionCallbacks; public: BlocksController(Level* level, uint padding);