fix MaterialDatabase::radiantLight null deref when material/matmod ID does not exist
This commit is contained in:
parent
a88b1e4ce0
commit
41bad6c97c
@ -89,14 +89,12 @@ inline LiquidSettingsConstPtr LiquidsDatabase::liquidSettings(LiquidId liquidId)
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline Vec3F LiquidsDatabase::radiantLight(LiquidLevel level) const {
|
inline Vec3F LiquidsDatabase::radiantLight(LiquidLevel level) const {
|
||||||
if (level.liquid >= m_settings.size())
|
if (level.liquid < m_settings.size()) {
|
||||||
return Vec3F();
|
if (auto const& settings = m_settings[level.liquid])
|
||||||
|
|
||||||
auto const& settings = m_settings[level.liquid];
|
|
||||||
if (!settings)
|
|
||||||
return Vec3F();
|
|
||||||
|
|
||||||
return settings->radiantLightLevel * level.level;
|
return settings->radiantLightLevel * level.level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Vec3F();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -239,13 +239,13 @@ inline Vec3F MaterialDatabase::radiantLight(MaterialId materialId, ModId modId)
|
|||||||
Vec3F radiantLight;
|
Vec3F radiantLight;
|
||||||
if (materialId < m_materials.size()) {
|
if (materialId < m_materials.size()) {
|
||||||
auto const& mat = m_materials[materialId];
|
auto const& mat = m_materials[materialId];
|
||||||
if (mat->materialRenderProfile)
|
if (mat && mat->materialRenderProfile)
|
||||||
radiantLight += mat->materialRenderProfile->radiantLight;
|
radiantLight += mat->materialRenderProfile->radiantLight;
|
||||||
}
|
}
|
||||||
if (modId < m_mods.size()) {
|
if (modId < m_mods.size()) {
|
||||||
auto const& mat = m_mods[modId];
|
auto const& mod = m_mods[modId];
|
||||||
if (mat->modRenderProfile)
|
if (mod && mod->modRenderProfile)
|
||||||
radiantLight += mat->modRenderProfile->radiantLight;
|
radiantLight += mod->modRenderProfile->radiantLight;
|
||||||
}
|
}
|
||||||
return radiantLight;
|
return radiantLight;
|
||||||
}
|
}
|
||||||
|
@ -1631,6 +1631,7 @@ RpcPromise<InteractAction> WorldClient::interact(InteractRequest const& request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WorldClient::lightingTileGather() {
|
void WorldClient::lightingTileGather() {
|
||||||
|
int64_t start = Time::monotonicMicroseconds();
|
||||||
Vec3F environmentLight = m_sky->environmentLight().toRgbF();
|
Vec3F environmentLight = m_sky->environmentLight().toRgbF();
|
||||||
float undergroundLevel = m_worldTemplate->undergroundLevel();
|
float undergroundLevel = m_worldTemplate->undergroundLevel();
|
||||||
auto liquidsDatabase = Root::singleton().liquidsDatabase();
|
auto liquidsDatabase = Root::singleton().liquidsDatabase();
|
||||||
@ -1638,7 +1639,6 @@ void WorldClient::lightingTileGather() {
|
|||||||
|
|
||||||
// Each column in tileEvalColumns is guaranteed to be no larger than the sector size.
|
// Each column in tileEvalColumns is guaranteed to be no larger than the sector size.
|
||||||
|
|
||||||
size_t lights = 0;
|
|
||||||
m_tileArray->tileEvalColumns(m_lightingCalculator.calculationRegion(), [&](Vec2I const& pos, ClientTile const* column, size_t ySize) {
|
m_tileArray->tileEvalColumns(m_lightingCalculator.calculationRegion(), [&](Vec2I const& pos, ClientTile const* column, size_t ySize) {
|
||||||
size_t baseIndex = m_lightingCalculator.baseIndexFor(pos);
|
size_t baseIndex = m_lightingCalculator.baseIndexFor(pos);
|
||||||
for (size_t y = 0; y < ySize; ++y) {
|
for (size_t y = 0; y < ySize; ++y) {
|
||||||
@ -1655,12 +1655,10 @@ void WorldClient::lightingTileGather() {
|
|||||||
if (tile.backgroundLightTransparent && pos[1] + y > undergroundLevel)
|
if (tile.backgroundLightTransparent && pos[1] + y > undergroundLevel)
|
||||||
light += environmentLight;
|
light += environmentLight;
|
||||||
}
|
}
|
||||||
if (light.max() > 0.0f)
|
|
||||||
++lights;
|
|
||||||
m_lightingCalculator.setCellIndex(baseIndex + y, light, !tile.foregroundLightTransparent);
|
m_lightingCalculator.setCellIndex(baseIndex + y, light, !tile.foregroundLightTransparent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
LogMap::set("client_render_world_async_light_tiles", toString(lights));
|
LogMap::set("client_render_world_async_light_gather", strf(u8"{:05d}\u00b5s", Time::monotonicMicroseconds() - start));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldClient::lightingCalc() {
|
void WorldClient::lightingCalc() {
|
||||||
|
Loading…
Reference in New Issue
Block a user