Hey.
I've got an exception that I can't figure out...
Unhandled exception at 0x1001fc79 in Earth.exe: 0xC0000005: Access violation reading location 0xbaad0034.
// Wrapper class for SDL_Surface that provides Copy-on-write semantics.
class Surface
{
public:
Surface() {}
Surface(const std::string& file_name, SDL_Colour* colour_key = NULL);
Surface& operator=(const Surface& rhs);
void Draw(Renderer& renderer, SDL_Rect position, SDL_Rect* clip = NULL);
Uint16 Width() const;
Uint16 Height() const;
private:
class Inner_Surface : public boost::noncopyable
{
public:
Inner_Surface() : surface(NULL) {}
Inner_Surface(SDL_Surface* surface) : surface(surface) {}
~Inner_Surface() { SDL_FreeSurface(surface); } // points to this line
SDL_Surface* surface;
};
boost::shared_ptr<Inner_Surface> inner;
};
My call stack looks like this:
Quote: SDL.dll!1001fc79()
[Frames below may be incorrect and/or missing, no symbols loaded for SDL.dll]
SDL.dll!100200a0()
SDL.dll!10026c7f()
> Earth.exe!Surface::Inner_Surface::~Inner_Surface() Line 36 + 0x2e bytes C++
Earth.exe!Surface::Inner_Surface::`scalar deleting destructor'() + 0x2b bytes C++
Earth.exe!boost::checked_delete<Surface::Inner_Surface>(Surface::Inner_Surface * x=0x00b3bc48) Line 34 + 0x2b bytes C++
Earth.exe!boost::detail::sp_counted_impl_p<Surface::Inner_Surface>::dispose() Line 79 + 0xc bytes C++
Earth.exe!boost::detail::sp_counted_base::release() Line 102 + 0xf bytes C++
Earth.exe!boost::detail::shared_count::~shared_count() Line 209 C++
Earth.exe!boost::shared_ptr<Surface::Inner_Surface>::~shared_ptr<Surface::Inner_Surface>() + 0x2e bytes C++
Earth.exe!Surface::~Surface() + 0x2b bytes C++
Earth.exe!XImage::~XImage() Line 33 + 0xb bytes C++
Earth.exe!XImage::`scalar deleting destructor'() + 0x2b bytes C++
Earth.exe!XScreen<Type_List<XImage,Type_List<XButton,Type_List<XSlider,Type_List<XDialog_Box,Null_Type> > > > >::~XScreen<Type_List<XImage,Type_List<XButton,Type_List<XSlider,Type_List<XDialog_Box,Null_Type> > > > >() Line 76 + 0x3b bytes C++
Earth.exe!Earth::~Earth() Line 35 + 0xa8 bytes C++
msvcr80d.dll!_CallSettingFrame(unsigned long funclet=1244980, unsigned long pRN=259, unsigned long dwInCode=939933583) Line 73 Asm
msvcr80d.dll!__FrameUnwindToState(EHRegistrationNode * pRN=0x0012ff34, void * pDC=0x0012eec4, const _s_FuncInfo * pFuncInfo=0x004bd598, int targetState=2) Line 1154 C++
msvcr80d.dll!CatchIt(EHExceptionRecord * pExcept=0x0012eef0, EHRegistrationNode * pRN=0x0012ff34, _CONTEXT * pContext=0x0012ef10, void * pDC=0x0012eec4, const _s_FuncInfo * pFuncInfo=0x004bd598, const _s_HandlerType * pCatch=0x004bd578, const _s_CatchableType * pConv=0x004bc08c, const _s_TryBlockMapEntry * pEntry=0x004bd5d0, int CatchDepth=0, EHRegistrationNode * pMarkerRN=0x00000000, unsigned char IsRethrow=0) Line 1264 + 0x17 bytes C++
msvcr80d.dll!FindHandler(EHExceptionRecord * pExcept=0x0012eef0, EHRegistrationNode * pRN=0x0012ff34, _CONTEXT * pContext=0x0012ef10, void * pDC=0x0012eec4, const _s_FuncInfo * pFuncInfo=0x004bd598, unsigned char recursive=0, int CatchDepth=0, EHRegistrationNode * pMarkerRN=0x00000000) Line 779 + 0x31 bytes C++
msvcr80d.dll!__InternalCxxFrameHandler(EHExceptionRecord * pExcept=0x0012eef0, EHRegistrationNode * pRN=0x0012ff34, _CONTEXT * pContext=0x0012ef10, void * pDC=0x0012eec4, const _s_FuncInfo * pFuncInfo=0x004bd598, int CatchDepth=0, EHRegistrationNode * pMarkerRN=0x00000000, unsigned char recursive=0) Line 529 + 0x25 bytes C++
msvcr80d.dll!__CxxFrameHandler3(EHExceptionRecord * pExcept=0x0012ff34, EHRegistrationNode * pRN=0x0012ef10, void * pContext=0x0012eec4, void * pDC=0x0012ff34) Line 365 + 0x1f bytes C++
ntdll.dll!7c9037bf()
ntdll.dll!7c90378b()
ntdll.dll!7c937860()
ntdll.dll!7c926abe()
ntdll.dll!7c96cde9()
ntdll.dll!7c90eafa()
kernel32.dll!7c812a5b()
kernel32.dll!7c812a5b()
ntdll.dll!7c90e9ab()
kernel32.dll!7c809524()
ntdll.dll!7c90e9ab()
kernel32.dll!7c8094e2()
ntdll.dll!7c926abe()
ntdll.dll!7c9268ad()
ntdll.dll!7c91056d()
dsound.dll!73f124df()
dsound.dll!73f124c1()
dsound.dll!73f1ea5b()
dsound.dll!73f1e9f9()
ntdll.dll!7c90e9ab()
kernel32.dll!7c812a5b()
msvcr80d.dll!_CxxThrowException(void * pExceptionObject=0x0012f2a4, const _s__ThrowInfo * pThrowInfo=0x004bc014) Line 166 C++
Earth.exe!Renderer::Blit_Surface(SDL_Rect position={...}, SDL_Surface * surface=0x01216448, SDL_Rect * clip=0x00000000) Line 159 + 0x92 bytes C++
Earth.exe!Surface::Draw(Renderer & renderer={...}, SDL_Rect position={...}, SDL_Rect * clip=0x00000000) Line 28 C++
Earth.exe!XImage::Draw(Renderer & renderer={...}) Line 57 C++
Earth.exe!XScreen<Type_List<XImage,Type_List<XButton,Type_List<XSlider,Type_List<XDialog_Box,Null_Type> > > > >::Draw(Renderer & renderer={...}) Line 85 + 0x29 bytes C++
Earth.exe!Earth::Run() Line 40 + 0x22 bytes C++
Earth.exe!SDL_main(int argc=1, char * * args=0x00b35da0) Line 29 C++
Earth.exe!_main() + 0xd1 bytes C
Earth.exe!__tmainCRTStartup() Line 586 + 0x19 bytes C
Earth.exe!mainCRTStartup() Line 403 C
kernel32.dll!7c816fd7()
I see that the first exception thrown was here:
void Renderer::Blit_Surface(
SDL_Rect position, SDL_Surface* surface, SDL_Rect* clip)
{
std::cout << "Last error was: " << SDL_GetError() << std::endl; // debugging only
bool successful = (SDL_BlitSurface(surface, clip, screen, &position) == 0);
if(!successful)
{ // Unsuccessful blit.
throw std::runtime_error(std::string(
"Surface failed to blit.\nSDL: ") + SDL_GetError());
}
}
Then, looking at that call stack again, it seems like everything starts to destruct but the Surface destructor is screwing up...
Can anyone see what is wrong with this?
Cheers.