I have a class that has a std::shared_ptr
as a member, which is later initialised in a function. However, I don't believe it's working correctly as when I debug it and inspect the layout of the shared_ptr object, it shows <Unable to read memory>
when I try to view the inner pointer (the class the shared_ptr
is pointing to).
The first three file snippets below are from a DLL project that a second project references. The IGLSLProgram.h file is included in this second project so that the exported class defined in the DLL can be used.
IGLSLProgram.h (Interface in the DLL)
class IGLSLProgram;
typedef IGLSLProgram *GLSLProgramHandle;
typedef shared_ptr<IGLSLProgram> IGLSLProgramPtr;
extern "C" COMMON_API GLSLProgramHandle APIENTRY getGLSLProgram();
class IGLSLProgram {
public:
IGLSLProgram() {}
~IGLSLProgram() {}
// ...
virtual void release() = 0;
};
GLSLProgram.h (Implements IGLSLProgram)
#include "IGLSLProgram.h"
class GLSLProgram : public IGLSLProgram {
public:
GLSLProgram() {}
~GLSLProgram() {}
// ...
void release();
};
GLSLProgram.cpp (Defines GLSLProgram implementation)
#include "GLSLProgram.h"
COMMON_API GLSLProgramHandle APIENTRY getGLSLProgram() {
return new GLSLProgram;
}
// ...
Program.h (Program that uses the DLL)
#include "Common\IProgram.h"
#include "Common\IGLSLProgram.h"
class Program : public IProgram {
protected:
IGLSLProgramPtr shaderProgram;
public:
Program() {}
~program() {}
void createShaderProgram();
// ...
};
Program.cpp (Defines class declared in Program.h)
#include "Program.h"
#include "Common\IGLSLProgram.h"
// ...
void Program::createShaderProgram() {
shaderProgram = IGLSLProgramPtr(getGLSLProgram(), mem_fn(&IGLSLProgram::release));
// ...
}
When inspecting the last line in the Program.cpp snippet, I see that shaderProgram has the following layout: http://i.stack.imgur.com/VZrkF.jpg
Any help with this issue would be greatly appreciated.