fix some UB
This commit is contained in:
parent
8aee8d81fb
commit
b5999fe364
@ -8,9 +8,12 @@
|
||||
#include "voxels/Block.hpp"
|
||||
#include "constants.hpp"
|
||||
#include "util/timeutil.hpp"
|
||||
#include "debug/Logger.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
static debug::Logger logger("lighting");
|
||||
|
||||
Lighting::Lighting(const Content& content, Chunks& chunks)
|
||||
: content(content), chunks(chunks) {
|
||||
auto& indices = *content.getIndices();
|
||||
@ -63,6 +66,10 @@ void Lighting::buildSkyLight(int cx, int cz){
|
||||
const auto blockDefs = content.getIndices()->blocks.getDefs();
|
||||
|
||||
Chunk* chunk = chunks.getChunk(cx, cz);
|
||||
if (chunk == nullptr) {
|
||||
logger.error() << "attempted to build sky lights to chunk missing in local matrix";
|
||||
return;
|
||||
}
|
||||
for (int z = 0; z < CHUNK_D; z++){
|
||||
for (int x = 0; x < CHUNK_W; x++){
|
||||
int gx = x + cx * CHUNK_W;
|
||||
@ -95,7 +102,10 @@ void Lighting::onChunkLoaded(int cx, int cz, bool expand) {
|
||||
|
||||
auto blockDefs = content.getIndices()->blocks.getDefs();
|
||||
auto chunk = chunks.getChunk(cx, cz);
|
||||
|
||||
if (chunk == nullptr) {
|
||||
logger.error() << "attempted to build lights to chunk missing in local matrix";
|
||||
return;
|
||||
}
|
||||
for (uint y = 0; y < CHUNK_H; y++){
|
||||
for (uint z = 0; z < CHUNK_D; z++){
|
||||
for (uint x = 0; x < CHUNK_W; x++){
|
||||
|
||||
@ -19,6 +19,7 @@ namespace lua {
|
||||
int userdata_destructor(lua::State* L);
|
||||
|
||||
std::string env_name(int env);
|
||||
void dump_stack(lua::State*);
|
||||
|
||||
inline bool getglobal(lua::State* L, const std::string& name) {
|
||||
lua_getglobal(L, name.c_str());
|
||||
@ -208,7 +209,7 @@ namespace lua {
|
||||
return lua_isnumber(L, idx);
|
||||
}
|
||||
inline bool isstring(lua::State* L, int idx) {
|
||||
return lua_isstring(L, idx);
|
||||
return lua_type(L, idx) == LUA_TSTRING;
|
||||
}
|
||||
inline bool istable(lua::State* L, int idx) {
|
||||
return lua_istable(L, idx);
|
||||
@ -226,6 +227,11 @@ namespace lua {
|
||||
return lua_toboolean(L, idx);
|
||||
}
|
||||
inline lua::Integer tointeger(lua::State* L, int idx) {
|
||||
#ifndef NDEBUG
|
||||
if (lua_type(L, idx) == LUA_TSTRING) {
|
||||
throw std::runtime_error("integer expected, got string");
|
||||
}
|
||||
#endif
|
||||
return lua_tointeger(L, idx);
|
||||
}
|
||||
inline uint64_t touinteger(lua::State* L, int idx) {
|
||||
@ -236,6 +242,11 @@ namespace lua {
|
||||
return static_cast<uint64_t>(val);
|
||||
}
|
||||
inline lua::Number tonumber(lua::State* L, int idx) {
|
||||
#ifndef NDEBUG
|
||||
if (lua_type(L, idx) != LUA_TNUMBER && !lua_isnoneornil(L, idx)) {
|
||||
throw std::runtime_error("integer expected");
|
||||
}
|
||||
#endif
|
||||
return lua_tonumber(L, idx);
|
||||
}
|
||||
inline const char* tostring(lua::State* L, int idx) {
|
||||
@ -588,7 +599,6 @@ namespace lua {
|
||||
}
|
||||
int create_environment(lua::State*, int parent);
|
||||
void remove_environment(lua::State*, int id);
|
||||
void dump_stack(lua::State*);
|
||||
|
||||
inline void close(lua::State* L) {
|
||||
lua_close(L);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user