This function works perfectly fine, or so the compiler/debugger tells me
void GUIManager::init(ToScreen* tS)
{
toScreen = tS;
loadFonts();
GUI_Surface = SDL_SetVideoMode( toScreen->width, toScreen->height, 32, SDL_SWSURFACE );
components.push_back(&PlainText("Hello, World!", font, -20, -40));
}
In here, the first function call raises an access violation error.
The debugger doesn’t show any problems.
I don’t get the chance to debug components[0], since the program halts here.
void GUIManager::draw()
{
// This line here is the problem
components[0].draw(GUI_Surface);
// This line here is the problem
SDL_BlitSurface(GUI_Surface, NULL, toScreen->Screen_Surface, NULL);
}
In case it’s needed, this is my ‘components’
boost::ptr_vector<GUIComponent> components;
Just let me know if any other code is needed. Perhaps that of PlainText, or GUIComponent
Instead of pushing pointer to temporary, which ends its lifetime just after this line:
You should push dynamic object, which will exist as long as
components:See doc: http://www.boost.org/doc/libs/1_51_0/libs/ptr_container/doc/ptr_sequence_adapter.html#modifiers