Improve memory safety of VRamList
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 2m5s

Copying it around is slow and you wouldn't do it. But incase some idiot actually does so it doesn't break everything.
This commit is contained in:
2024-10-05 20:14:46 -04:00
parent a568faa701
commit b4c29315f4
2 changed files with 22 additions and 1 deletions

View File

@@ -21,12 +21,17 @@ private:
void SetData(void* data, const long& length); void SetData(void* data, const long& length);
void UpdateData(void* data, const long& offset, const long& length); void UpdateData(void* data, const long& offset, const long& length);
public: public:
VRamList() = default;
VRamList(const GLuint* data, const long& length); VRamList(const GLuint* data, const long& length);
VRamList(const GLfloat* data, const long& length); VRamList(const GLfloat* data, const long& length);
VRamList(Vector2* data, const long& length); VRamList(Vector2* data, const long& length);
VRamList(Vector3* data, const long& length); VRamList(Vector3* data, const long& length);
VRamList(Vector4* data, const long& length); VRamList(Vector4* data, const long& length);
~VRamList();
/** Copying around the VBO data to a new VBO like this is slow.
* Pass to function by const reference or pointer always. */
VRamList(const VRamList& rhs);
public: public:
[[nodiscard]] GLuint GetHandle() const; [[nodiscard]] GLuint GetHandle() const;
/// Returns the number of elements in the list. /// Returns the number of elements in the list.

View File

@@ -40,6 +40,7 @@ void JGL::VRamList::Erase() {
JGL::Logger::Warning("Erasing an array buffer while it's in use?"); JGL::Logger::Warning("Erasing an array buffer while it's in use?");
glDeleteBuffers(1, &list_handle); glDeleteBuffers(1, &list_handle);
list_handle = 0;
} }
GLuint JGL::VRamList::GetHandle() const { GLuint JGL::VRamList::GetHandle() const {
@@ -250,3 +251,18 @@ void JGL::VRamList::UpdateData(const GLuint* data, const long& offset, const lon
void JGL::VRamList::UpdateData(const Vector2i* data, const long& offset, const long& length) { void JGL::VRamList::UpdateData(const Vector2i* data, const long& offset, const long& length) {
UpdateData((void*) data, offset, length * 2); UpdateData((void*) data, offset, length * 2);
} }
JGL::VRamList::~VRamList() {
Erase();
}
JGL::VRamList::VRamList(const JGL::VRamList& rhs) {
if (rhs.element_array_buffer) {
auto data_array = rhs.GetDataUI();
this->load(data_array.data(), data_array.size());
return;
}
auto data_array = rhs.GetDataF();
this->load(data_array.data(), data_array.size());
}