Skip to content

Commit

Permalink
Fixed segfault caused by incorrect indexing while importing a mesh node.
Browse files Browse the repository at this point in the history
  • Loading branch information
hamsham committed Feb 14, 2022
1 parent d887b39 commit e281f3e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion softlight/src/SL_SceneGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ size_t SL_SceneGraph::insert_mesh_node(
mNumNodeMeshes.push_back(numSubMeshes);

SL_SceneNode node;
node.dataId = mNodeMeshes.size();
node.dataId = mNodeMeshes.size() - 1;
node.type = SL_SceneNodeType::NODE_TYPE_MESH;

mNodeParentIds.push_back(parentId);
Expand Down
15 changes: 5 additions & 10 deletions softlight/src/SL_TextMeshLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,21 +536,16 @@ unsigned SL_TextMeshLoader::allocate_cpu_data(const std::string& str, const SL_C
}

{
sceneData.mNodes.push_back(SL_SceneNode{SL_SceneNodeType::NODE_TYPE_MESH, 0});
sceneData.mNodeParentIds.push_back(SCENE_NODE_ROOT_ID);
sceneData.mBaseTransforms.emplace_back(math::mat4{1.f});
sceneData.mCurrentTransforms.emplace_back(SL_Transform{math::mat4{1.f}, SL_TRANSFORM_TYPE_MODEL});
sceneData.mModelMatrices.emplace_back(math::mat4{1.f});
sceneData.mNodeNames.emplace_back(std::string{"textMesh-"} + std::to_string(utils::hash_fnv1(str.c_str())));

sceneData.mNodeMeshes.emplace_back(new size_t[numSubmeshes]);
ls::utils::Pointer<size_t[]>& meshIds = sceneData.mNodeMeshes[0];
SL_Transform transform = SL_Transform{math::mat4{1.f}, SL_TRANSFORM_TYPE_MODEL};
const std::string&& meshName = std::string{"textMesh-"} + std::to_string(utils::hash_fnv1(str.c_str()));
ls::utils::Pointer<size_t[]> meshIds{new size_t[numSubmeshes]};

for (unsigned sm = 0; sm < numSubmeshes; ++sm)
{
meshIds[sm] = sm;
}

sceneData.mNumNodeMeshes.push_back(numSubmeshes);
sceneData.insert_mesh_node(SCENE_NODE_ROOT_ID, meshName.c_str(), numSubmeshes, meshIds.get(), transform);
}

numBytes += (unsigned)(sizeof(SL_Mesh) * meshes.size());
Expand Down

0 comments on commit e281f3e

Please sign in to comment.