1
0

Avoid a crash in drawMeshNode() after reading out of array

* backported from b201316aed
This commit is contained in:
mckaygerhard 2024-06-02 04:20:34 -04:00
parent f783bdb170
commit bf186d81b1
4 changed files with 17 additions and 4 deletions

View File

@ -1420,9 +1420,14 @@ void MapblockMeshGenerator::drawMeshNode()
// Convert wallmounted to 6dfacedir.
// When cache enabled, it is already converted.
facedir = n.getWallMounted(nodedef);
if (!enable_mesh_cache)
facedir = wallmounted_to_facedir[facedir];
if (!enable_mesh_cache) {
facedir = wallmountedToFacedir(facedir);
}
}
// f->mesh_ptr has 24 elements
if (facedir > 23)
facedir = 0;
if (!data->m_smooth_lighting && f->mesh_ptr[facedir]) {
// use cached meshes

View File

@ -151,7 +151,7 @@ u8 MapNode::getFaceDir(const NodeDefManager *nodemgr,
return (getParam2() & 0x1F) % 24;
if (allow_wallmounted && (f.param_type_2 == CPT2_WALLMOUNTED ||
f.param_type_2 == CPT2_COLORED_WALLMOUNTED))
return wallmounted_to_facedir[getParam2() & 0x07];
return wallmountedToFacedir(getParam2() & 0x07);
return 0;
}

View File

@ -118,3 +118,11 @@ const u8 wallmounted_to_facedir[6] = {
8,
4 + 2
};
const u8 wallmountedToFacedir(u8 index)
{
if (index > 5)
return 0;
else
return wallmounted_to_facedir[index];
}

View File

@ -31,7 +31,7 @@ extern const v3s16 g_26dirs[26];
// 26th is (0,0,0)
extern const v3s16 g_27dirs[27];
extern const u8 wallmounted_to_facedir[6];
extern const u8 wallmountedToFacedir(u8 index);
/// Direction in the 6D format. g_27dirs contains corresponding vectors.
/// Here P means Positive, N stands for Negative.