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:
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?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;
}
It ran perfectly when it used a vector of SDL_Surfaces instead of a vector of renderlist_entry structures.

