chore: delete uniforms if they already exist before setting

This commit is contained in:
Almamu 2025-04-25 20:40:26 +02:00
parent aeb50e8e82
commit c59c466674

View File

@ -617,6 +617,13 @@ template <typename T> void CPass::addUniform (const std::string& name, UniformTy
if (id == -1)
return;
// free the uniform that's already registered if it's there already
const auto it = this->m_uniforms.find (name);
if (it != this->m_uniforms.end ()) {
delete it->second;
}
// build a copy of the value and allocate it somewhere
T* newValue = new T (value);
@ -632,6 +639,13 @@ template <typename T> void CPass::addUniform (const std::string& name, UniformTy
if (id == -1)
return;
// free the uniform that's already registered if it's there already
const auto it = this->m_uniforms.find (name);
if (it != this->m_uniforms.end ()) {
delete it->second;
}
// uniform found, add it to the list
this->m_uniforms.insert_or_assign (name, new UniformEntry (id, name, type, value, count));
}
@ -644,6 +658,13 @@ template <typename T> void CPass::addUniform (const std::string& name, UniformTy
if (id == -1)
return;
// free the uniform that's already registered if it's there already
const auto it = this->m_uniforms.find (name);
if (it != this->m_uniforms.end ()) {
delete it->second;
}
// uniform found, add it to the list
this->m_referenceUniforms.insert_or_assign (
name, new ReferenceUniformEntry (id, name, type, reinterpret_cast<const void**> (value)));
@ -684,15 +705,15 @@ void CPass::addUniform (CShaderVariable* value) {
void CPass::addUniform (CShaderVariable* value, const CDynamicValue* setting) {
if (value->is<CShaderVariableFloat> ()) {
this->addUniform (value->getName (), setting->getFloat ());
this->addUniform (value->getName (), &setting->getFloat ());
} else if (value->is<CShaderVariableInteger> ()) {
this->addUniform (value->getName (), setting->getInt ());
this->addUniform (value->getName (), &setting->getInt ());
} else if (value->is<CShaderVariableVector2> ()) {
this->addUniform (value->getName (), setting->getVec2 ());
this->addUniform (value->getName (), &setting->getVec2 ());
} else if (value->is<CShaderVariableVector3> ()) {
this->addUniform (value->getName (), setting->getVec3 ());
this->addUniform (value->getName (), &setting->getVec3 ());
} else if (value->is<CShaderVariableVector4> ()) {
this->addUniform (value->getName (), setting->getVec4 ());
this->addUniform (value->getName (), &setting->getVec4 ());
} else {
sLog.error ("Cannot convert setting dynamic value to ", value->getName (), ". Using default value");
}