SDL Forum Index
SDL
Simple DirectMedia Layer Forums
Reply to topic
General programming question - please help!
throwaway83


Joined: 31 Oct 2016
Posts: 2
Reply with quote
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)
return;
if(lbindex >= mWindow[winindex].mNumListBoxes)
return;
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.
View user's profileSend private message
throwaway83


Joined: 31 Oct 2016
Posts: 2
Reply with quote
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:

GGUI_Interface::ListBox::~ListBox()
{
free();
}

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.
View user's profileSend private message
General programming question - please help!
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic