General programming question - please help!


Hi… I’m new here. I’m encountering a problem. Here’s a segment of code that’s giving me the problem:

void GGUI_Interface::setListBoxOption(int winindex, int lbindex, int option, std::string label)
if(lbindex < 0 || winindex < 0 || winindex >= 40)
if(lbindex >= mWindow[winindex].mNumListBoxes)
std::cout << mWindow[winindex].mListBox[lbindex].mHighlighted << std::endl;
mWindow[winindex].mListBox[lbindex].setOption(option, label, mFont, mRenderer);

Now I print out to console to prove that the object I’m pointing at exists, but when I run the program the last line in the function produces a segmentation fault error. The std::cout line prints -1 (which is what the object initializes to when created).

What could be the source of this? When I tested this object earlier, it worked just fine, and I’ve done nothing different. This is giving me a headache.


Additional weirdness… if I remove the call to the function that is causing the problem, the program will start, but when I close the program and the destructor for the listbox object is called, I get another segmentation fault error from the following:


Does the segmentation fault mean that the problem lies within the offending function, rather than the function call itself? Both of these functions manipulate text pointers. I’m using an array of SDL_Texture* pointers, maybe that is the source of the problem. The only thing is, I tested this before and the listbox worked fine, and the function calls to create and allocate memory for the listbox are no different.