vblanco20-1 / vulkan-guide

Introductory guide to vulkan.
https://vkguide.dev/
MIT License
909 stars 205 forks source link

[CVar system] Memory leak inside the code example + typo inside the article #80

Open Vin789 opened 1 year ago

Vin789 commented 1 year ago

Hi !

First, thx a lot for all your articles and code examples they are really useful. I'm integrating a CVar system based on your example inside my own engine and I think I found a trivial memory leak inside the example code here:

https://github.com/vblanco20-1/vulkan-guide/blob/engine/extra-engine/cvars.cpp

Line 49 you are doing a dynamic allocation for the CVarStorage array but you never delete this array inside the code. Adding:

~CVarArray()
{
    delete[] cvars;
    cvars = nullptr;
}

Right after the constructor should fix the issue if ever you want to fix it.

Also inside the article:

//checkbox CVAR
AutoCVar_Int CVAR_TestCheckbox("test.checkbox", "just a checkbox", 0, CVarFlags::EditCheckbox);

//int CVAR
AutoCVar_Int CVAR_TestInt("test.int", "just a configurable int", 42);

//float CVAR
AutoCVar_Int CVAR_TestFloat("test.float", "just a configurable float", 13.37);

//string CVAR
AutoCVar_String CVAR_TestString("test.string", "just a configurable string", "just a configurable string");

There is a small typo for the float CVar example. It Should use AutoCVar_Float instead of AutoCVar_Int (it won't compile anyway as the last argument is a double and not an int). Again it's trivial if ever you want to fix it.

Thx again for all the resources.