TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 229 subscribers
Post #24525 26
5hrs spent debugging just to find out i forgot to initialize to 0 in class.

Yup, it finally happened.

I am making a voxel terrain generation project to learn OpenGL. It was my abstraction of vertex arrays. Initially, when I created this class, it generated an ID in the constructor, but then when I introduced multithreading, I needed to stop doing that in the constructor (bad design, I know—need to study design patterns). So I introduced a boolean to initialize it when the first call to Bind() is made. But I didn't set it to false at that time. I saw chunks rendering, but there were gaps between them. So I started debugging, and honestly, the VertexArray class wasn't even on my mind. I just printed the VAO values in the output along with some other data. Although the values were somewhat random, I ignored it because OpenGL only guarantees unique unused values, not how they're generated. But then in the middle, I saw some were small and continuous like 1, 2, ..., 10. Then I put a print statement in the Generate() function of VertexArray and realized it wasn't even being called.

Yup, that's my rant. And here's the ugly code I wrote:

cpp

class VertexArray {
public:
explicit VertexArray(bool lazy = false);
~VertexArray();

// Returns the vertex array ID
GLuint id() const { return arrayid; }
void Generate();

// Binds this vertex array
void Bind();
void UnBind();

// Adds and enables the attribute
void AddAttribute(Attribute attribute);

private:
GLuint arrayid{};
};

https://redd.it/1prafjr
@r_cpp
Reddit From the cpp community on Reddit Explore this post and more from the cpp community
More from @r_cpp
  1. Oct 9, 2026std::variant, operator== and pattern matching I was thinking, wouldn't adding equality com…
  2. Oct 8, 2026Profiles for simplicity and guarantees - Bjarne Stroustrup - CppCon 2026 https://youtu.be/…
  3. Oct 8, 2026How to Fix autoconf-style Configuration Probing https://build2.org/blog/fix-autoconf.xhtml…
  4. Oct 8, 2026owl – a header-only C++23 HTTP framework where route patterns and handler extractors are c…
  5. Oct 8, 2026Removed by Reddit Removed by Reddit on account of violating the [content policy. ] https:/…
  6. Oct 8, 2026Is there a way to search across all P and N papers throughout standardization history? It…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →