Hello everyone,
generally I avoid asking questions here. Usually I just track the problem and eventually find the bug by myself. But right now, I'm pretty sure I know where bug is and I will find it, but I'm not asking about how to fix a bug.
I'm asking why something is happening.
Let me show you a bit of my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
//Menu.cpp
//code...
void Menu::PrepareOptions(int& options/*options flags*/)
{
int pos = 1;//First block will be at first position
//optionsBlocks is of type std::vector<Block*>
if( options & OPTION_START )
{
optionsBlocks.push_back( new Button(*_win, "Start.png", CHOICE_START, pos++) );
}
if ( options & OPTION_RETURN )
{
optionsBlocks.push_back( new Button(*_win, "Return.png", CHOICE_RETURN, pos++) );
}
if( options & OPTION_HELP )
{
optionsBlocks.push_back( new Button(*_win, "Help.png", CHOICE_HELP, pos++) );
}
if ( options & OPTION_CREDITS )
{
optionsBlocks.push_back( new Button(*_win, "Credits.png", CHOICE_CREDITS, pos++) );
}
if ( options & OPTION_OPTIONS )
{
optionsBlocks.push_back( new Button(*_win, "Options.png", CHOICE_OPTIONS, pos++) );
}
//Logger::Get()->Log("123456789ABCDEFF");
//If I add this call here, Exit button will be rendered in top left screen(with x=0 and y=0)
//If I won't, exit will still be pushed back, but it won't have proper position, so it won't be rendered
if ( options & OPTION_EXIT )
{
optionsBlocks.push_back( new Button(*_win, "Exit.png", CHOICE_EXIT, pos++) );
}
//Wheter logger will log anything here or not, it does not matter.
}
| |
1 2 3 4 5 6 7
|
//Logger.hpp
//code...
//logText is of type std::ofstream
void Logger::Log(std::string logText)
{
log << logText << std::endl;
}
| |
So that's the code. As comments in Menu.hpp explained - currently I have a bug - last button("Exit"), is not rendered, nor present in menu screen(I click everywhere, but it doesn't interact; it's simply not there).
It's okay. I started tracking this bug with logger, and found out interesting thing - if I log 16 chars long or longer string after creating 3rd button(CREDITS), but before creating Exit button, Exit button will indeed be rendered and I can even click on it. It works just good, it just has bad position - it's positioned in upper left corner(so it has x=0 and y=0).
However, if I log anywhere in between these buttons(so e.g. after creating 2nd one but before 3rd, before creating 1st button, or after creating exit button), nothing will happen. Exit will still not be visible nor functioning.
I thought it may be depending on time, but I'm not sure if it works - I used SDL_Delay, and it didn't work. Only logger is making Exit real.
Logger is singleton, and it's not depending nor modifying any external data, except std::ofstream.
If you need some more code please let me know. I just want to understand, why logger is causing this behavior, especially if it's not changing any values, and why it needs exactly 16 characters(without '\0') to make Exit button renderable.