15
kerith
8y

I am working on an open source game project, and the most common way to draw things is using a class named ManagedSurface. The class is otherwise awesome, but it has a method called getBasePtr(x, y), which gives you a pointer to the requested coordinates. Fair enough (this is C++ without STL by the way).

But WHY THE HELL CAN I REQUEST ANY POINTER THAT I WANT, EVEN IF IT'S OUTSIDE THE SURFACE? Other cointainers have sanity checks, asserts and such, and the surface KEEPS TRACK OF IT'S WIDTH AND HEIGHT.

WAS IT SO FUCKING HARD TO ADD assert(x <= w); assert(y <= h);???

I spent 3 days on valgrind trying to find a heap corruption that manifested at random points in the code.

FUUUUCK!

On the bright side, I learned how to use valgrind (which is awesomely awesome).

Comments
  • 1
    I'm not sure what heap corruption has to do with points outside the container. It's not uncommon for drawing libraries to let you specify points beyond the bounds. In iOS, you can specify any x,y you'd like. There's a separate method for detecting if points are within a rect.

    Perhaps you could add a method that checks if the point is inside the rectangle? And then you could add another method that does both the call to retrieve the coordinate pointer, and checks that the point is within the bounds.
  • 0
    can tou share the url to this project? id like to study it
  • 0
    @liveCoder sure :) it's scummvm.org
  • 1
    I didn't know it was common :).

    anyways, it's certainly my fault for writing outside the surface, I was just venting at my frustration with myself. Once I figured out that writing outside bounds was the problem, it was easy to fix.

    @benrooke
Add Comment