Thursday, July 15, 2010

Week Three / Day Three and Four

The last two days have not been very good development days. Given that game development was going to be the biggest leap I've ever made with programming, I knew I would hit snags; big snags like the one that is plaguing me now. My game world uses a class called objects, which right now contains only a vector< vertex > for storing the vertices that make up the model. It also only contains one method right now to construct an object, a cone. My rendering class then contains a vector< object* > to dynamically allocate a set of cones at run time with a loop that runs during the initialization of the instantiated rendering class object. So far, so good. A few tests show that accessing this vector of object pointers within the init method returns no errors. Now, once I get into the actual draw calls in the render class via a render method, everything hits the fan. I cannot for the life of me stop getting weird invalid memory access errors within the vectors when I try and loop through and draw each of the objects dynamically created. If I don't use pointers, and instead create the objects in a vector< object>, everything works fine, but that is far too rigid. To put that sort of limitation in my project at such an early (and deep) stage is extremely poor design as the world generator is going to be creating, deleting and passing around objects all over the place. I'd really like to be able to work with pointers for their flexibility in what I want to do. Unfortunately, it has become very clear to me that I don't have a strong enough understanding of the standard template library. A bit of research earlier today revealed than when working with something as dense and structurally complex as a vector of class pointers which contain vectors of structs themselves, which is what I'm doing, what you see is not what you get. Many precautions need to be taken when digging around with that much memory and at the level I am, and it's apparent to me that I don't really know what all those precautions are. As Uncle Ben once said, with great power comes great responsibility. This is the longest a bug has ever taken me to fix, and it's extremely frustrating, but I'm hoping the education I get while solving it will be valuable information I end up using again and again.

No comments:

Post a Comment