Problem with glGetInfoLogARB and auto_ptr

Started by
1 comment, last by rick_appleton 18 years, 10 months ago
I'm trying to read a log from a compilation of a GLSL shader. Using a normal buffer, this works fine. However, since I am using exceptions, I'd like to make the function atomic, and to do this, I've tried to use a std::auto_ptr to retrieve the log.

int infoLogLength = 0;
glGetObjectParameterivARB(shaderID, GL_OBJECT_INFO_LOG_LENGTH_ARB, &infoLogLength);

// This works
char *buffer = new char[infoLogLength];
glGetInfoLogARB(shaderID, infoLogLength, 0, buffer);

// This crashes
std::auto_ptr<char> buffera = new char[infoLogLength];
glGetInfoLogARB(shaderID, infoLogLength, 0, buffera.get());
I would like to use the second piece, but it crashes somewhere in my ATI driver. The first piece works like it should, but could leak memory if something goes wrong. It's probably something to do with the auto_ptr, but since I don't have a lot of experience with them, I haven't been able to fix this. Any ideas?
Advertisement
I don't see why that should not work. Except that it should be:

std::auto_ptr<char> buffera(new char[infoLogLength]);

As you posted it, it does not compile.

Try using a vector and see if that works, like:

std::vector<char> buffera;
buffera.resize(infoLogLength);
glGetInfoLogARB(shaderID, infoLogLength, 0, &*buffera.begin());





super genius
It's strange because that code did compile on Visual C++ Express Beta 2.

But your fix did work. I was just using the auto_ptr incorrectly. Thanks.

This topic is closed to new replies.

Advertisement