Fixed memory leak when deleting Effect

This commit is contained in:
Simon Lübeß
2024-08-24 20:09:22 +02:00
parent b98de9835d
commit ad73abd4ea
10 changed files with 139 additions and 176 deletions
+1 -53
View File
@@ -1,63 +1,11 @@
using DirectX.D3D11Shader;
using System;
using System.Collections;
using GlitchyEngine.Math;
using DirectX.D3D11Shader;
using internal GlitchyEngine.Renderer;
namespace GlitchyEngine.Renderer
{
public class BufferVariableCollection : IEnumerable<BufferVariable>
{
protected bool _ownsVariables = true;
protected List<BufferVariable> _variables = new .();
protected Dictionary<String, BufferVariable> _nameToVariable = new .() ~ delete _;
public this(bool ownsVariables = true)
{
_ownsVariables = ownsVariables;
}
public ~this()
{
if(_ownsVariables)
DeleteContainerAndItems!(_variables);
else
delete _variables;
}
public void Add(BufferVariable ownVariable)
{
_variables.Add(ownVariable);
_nameToVariable.Add(ownVariable.Name, ownVariable);
}
public bool TryAdd(BufferVariable ownVariable)
{
if(_nameToVariable.TryAdd(ownVariable.Name, ownVariable))
{
_variables.Add(ownVariable);
return true;
}
else
{
return false;
}
}
public bool TryGetVariable(String name, out BufferVariable variable)
{
return _nameToVariable.TryGetValue(name, out variable);
}
public BufferVariable this[String name] => _nameToVariable[name];
public List<BufferVariable>.Enumerator GetEnumerator()
{
return _variables.GetEnumerator();
}
}
public class ConstantBuffer : Buffer
{
protected String _name ~ delete _;