Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8598779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:14:09+00:00 2026-06-12T01:14:09+00:00

This function works perfectly fine, or so the compiler/debugger tells me void GUIManager::init(ToScreen* tS)

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:14:10+00:00Added an answer on June 12, 2026 at 1:14 am

    Instead of pushing pointer to temporary, which ends its lifetime just after this line:

    components.push_back(&PlainText("Hello, World!", font, -20, -40));
    

    You should push dynamic object, which will exist as long as components:

    components.push_back(new PlainText("Hello, World!", font, -20, -40));
    

    See doc: http://www.boost.org/doc/libs/1_51_0/libs/ptr_container/doc/ptr_sequence_adapter.html#modifiers

    void push_back( T* x ); 
        Requirements: x != 0 
        Effects: Inserts the pointer into container and takes ownership of it
        Throws: bad_pointer if x == 0
        Exception safety: Strong guarantee
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to plot some cities on Google's Geochart. This function works perfectly fine
I have this function in javascript file which works perfectly fine in Firefox /
This function works fine: std::string get_str() { return std::get<0>( make_tuple(std::string(hi)) ); } But if
This function works fine if I disable errors. But I have to solve them.
I am using this jquery function that works fine in win/mac FF 3.5 and
I've been working on custom Vector class. Everything works perfectly fine on Microsoft compiler,
I have setup a jquery based marquee, This works perfectly fine until I have
This is kind of a brainteaser question, since the code works perfectly fine as-is,
This function works as it should, window.setInterval(function(){ var active = $('#frontpageControls a.active'); var next
Can someone elaborate how this function works? Does it load every time from disk

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.