mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-12 06:21:50 +00:00
fix fatal error when skeleton is missing
This commit is contained in:
parent
b2df0a7e91
commit
8b5261f4f1
3 changed files with 16 additions and 5 deletions
|
|
@ -36,6 +36,9 @@ static rigging::Skeleton* get_skeleton(lua::State* L) {
|
||||||
|
|
||||||
static int l_get_model(lua::State* L) {
|
static int l_get_model(lua::State* L) {
|
||||||
if (auto skeleton = get_skeleton(L)) {
|
if (auto skeleton = get_skeleton(L)) {
|
||||||
|
if (skeleton->config == nullptr) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
auto& rigConfig = *skeleton->config;
|
auto& rigConfig = *skeleton->config;
|
||||||
auto index = index_range_check(*skeleton, lua::tointeger(L, 2));
|
auto index = index_range_check(*skeleton, lua::tointeger(L, 2));
|
||||||
const auto& modelOverride = skeleton->modelOverrides[index];
|
const auto& modelOverride = skeleton->modelOverrides[index];
|
||||||
|
|
@ -96,6 +99,9 @@ static int l_set_texture(lua::State* L) {
|
||||||
|
|
||||||
static int l_index(lua::State* L) {
|
static int l_index(lua::State* L) {
|
||||||
if (auto skeleton = get_skeleton(L)) {
|
if (auto skeleton = get_skeleton(L)) {
|
||||||
|
if (skeleton->config == nullptr) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if (auto bone = skeleton->config->find(lua::require_string(L, 2))) {
|
if (auto bone = skeleton->config->find(lua::require_string(L, 2))) {
|
||||||
return lua::pushinteger(L, bone->getIndex());
|
return lua::pushinteger(L, bone->getIndex());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ void Entities::loadEntity(const dv::value& map, Entity entity) {
|
||||||
if (map.has(COMP_TRANSFORM)) {
|
if (map.has(COMP_TRANSFORM)) {
|
||||||
transform.deserialize(map[COMP_TRANSFORM]);
|
transform.deserialize(map[COMP_TRANSFORM]);
|
||||||
}
|
}
|
||||||
if (skeleton == nullptr) {
|
if (skeleton == nullptr || skeleton->config == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::string skeletonName = skeleton->config->getName();
|
std::string skeletonName = skeleton->config->getName();
|
||||||
|
|
@ -397,6 +397,9 @@ void Entities::renderDebug(
|
||||||
ctx.setLineWidth(2);
|
ctx.setLineWidth(2);
|
||||||
for (auto [entity, transform, skeleton] : view.each()) {
|
for (auto [entity, transform, skeleton] : view.each()) {
|
||||||
auto config = skeleton.config;
|
auto config = skeleton.config;
|
||||||
|
if (config == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const auto& pos = transform.pos;
|
const auto& pos = transform.pos;
|
||||||
const auto& size = transform.size;
|
const auto& size = transform.size;
|
||||||
if (frustum && !frustum->isBoxVisible(pos - size, pos + size)) {
|
if (frustum && !frustum->isBoxVisible(pos - size, pos + size)) {
|
||||||
|
|
@ -434,9 +437,11 @@ void Entities::render(
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto* rigConfig = skeleton.config;
|
const auto* rigConfig = skeleton.config;
|
||||||
rigConfig->render(
|
if (rigConfig) {
|
||||||
assets, batch, skeleton, transform.rot, pos, size
|
rigConfig->render(
|
||||||
);
|
assets, batch, skeleton, transform.rot, pos, size
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ dv::value Entity::serialize() const {
|
||||||
root[COMP_RIGIDBODY] =
|
root[COMP_RIGIDBODY] =
|
||||||
rigidbody.serialize(def.save.body.velocity, def.save.body.settings);
|
rigidbody.serialize(def.save.body.velocity, def.save.body.settings);
|
||||||
|
|
||||||
if (skeleton != nullptr) {
|
if (skeleton != nullptr && skeleton->config != nullptr) {
|
||||||
if (skeleton->config->getName() != def.skeletonName) {
|
if (skeleton->config->getName() != def.skeletonName) {
|
||||||
root["skeleton-name"] = skeleton->config->getName();
|
root["skeleton-name"] = skeleton->config->getName();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue