Results 1 to 3 of 3

Thread: Vector structure issues

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    15

    Vector structure issues

    EDIT: Ack! Oops, I meant to post this in the other C++ forum! Could someone please move this?

    So I'm messing around with SDL in C++ a bit. I've written a function to add a surface to a vector of a structure. Like so:


    Code:
    struct renderlist_entry
    {
        SDL_Surface *surface;
        float x;
        float y;
        float w;
        float h;
    };
    
    vector<renderlist_entry*> renderlist;
    
    ... blah blah ...
    
    
    int add_to_render_list(const char* filename, float x, float y, float w, float h)
    {
        /* First we should ensure that the file can be loaded. */
        SDL_Surface *tmp_surface;
        renderlist_entry *entry;
    
        // Load the file first.
        tmp_surface = IMG_Load(filename);
        if (tmp_surface == NULL)
        {
            cerr << "Bad image was attempted to load: " << filename << "\nAbort load.\n";
            return 0;
        }
        cout << "test\n";
        entry->surface = tmp_surface;
        entry->x = x;
        entry->y = y;
        entry->w = w;
        entry->h = h;
        cout << "and again.\n";
        renderlist.push_back(entry); // Add the surface to the texturelist vector.
        return 1;
    }
    After the "cout << "test"", the app crashes (it compiled fine, by the way). The cerr is never called (so the surface loads fine). What might be wrong with the code between the two cout's?

    It ran perfectly when it used a vector of SDL_Surfaces instead of a vector of renderlist_entry structures.
    Last edited by _person_; Feb 22nd, 2011 at 11:59 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width