16
General / Re: Closing window causes access violation
« on: October 21, 2011, 02:02:32 pm »Quote from: "sbroadfoot90"
care to show your code?
Sure.. in fact while trying to get together some code to post here, I've found exact place where this happens. It happens when I call single function in my first program with 2 windows (the second one is out because it had the very same error but it was because of one vector).
This is the code for rendering second window, which is something like child to first, because it closes when the first one closes.
Code: [Select]
void SettingsUI::Render(){
window.SetActive();
window.Clear(sf::Color(0,0,0));
sf::Text text;
text.SetCharacterSize(20);
text.SetColor(sf::Color(30, 255, 30));
unsigned int i;
for(i = 0; i < menuSize; i++){
text.SetString(menuText[i]);
text.SetPosition(10.f, i*25.f+10.f);
window.Draw(text);
}
text.SetString("Input: " + input);
text.SetPosition(10.f, i*25.f+30.f);
window.Draw(text);
window.Display();
window.SetActive(false);
}
If I won't call this from my main function, the program ends without error. Playing with those commands I found that the only line causing trouble is:
Code: [Select]
window.Draw(text);
If you comment both of them away, text is not displayed but no error occurs on closing.It may help to say that I initialize window this way:
Code: [Select]
window.Create(sf::VideoMode(500, 300, 32), "Settings", sf::Style::Titlebar);
and close like this:
Code: [Select]
void SettingsUI::Close(){
window.Close();
menuText.clear();
waveEngine = 0;
}
Also note that
Code: [Select]
std::vector<sf::String> menuText;
sf::String input;