v0.7 error when trying to add radio button

Started by starkhorn, 05 September 2015, 23:44:26

starkhorn

So I am trying to add radio buttons using the black.txt file.
I've setup the theme as per the themes tutorial. (https://tgui.eu/tutorials/v0.7/using-themes/)

I have been able to create panels and labels without issue, but the radiobutton throws an error. I am using visual studio 2013 and I don't have a tgui.pdb so when it fails, I don't see the exact source line it fails. I get a Expression: pFirstBlock ==pHead error in the dbgheap.c.

My function is below and it fails at the "tgui::RadioButton::Ptr radioButton = theme->load("RadioButton");" line.

Code (cpp) Select

void Test::setupRadioButton(sf::Vector2i pos, sf::Vector2i size, sf::Color passed_colour, vector<string> stringList, tgui::Container::Ptr container)
{
int yposIncrementer = 0;

for (int i = 0; i < stringList.size(); i++)
{
if (container != NULL && container->get(stringList[i]) == NULL)
{
tgui::RadioButton::Ptr radioButton = theme->load("RadioButton");
radioButton->setPosition(pos.x, pos.y + yposIncrementer);
radioButton->setSize(size.x, size.y);
radioButton->getRenderer()->setTextColor(passed_colour);
if (stringList.size() > 0)
{
radioButton->setText(stringList[i]);
}
container->add(radioButton, stringList[i]);
yposIncrementer += size.y;
}
}
}


Here is a full working example. The drawLoadingScreen method which uses a panel with labels works fine. However the drawMainMenu fails when I try to add a radiobutton. Am I doing something wrong here?

Code (cpp) Select

#include <TGUI/TGUI.hpp>
#include <string>
#include <math.h>
#define THEME_CONFIG_FILE "C:\\Programming\\Debug\\widgets\\Black.txt"

using namespace std;

class Test
{
public:

Test();

sf::RenderWindow gameWindow;
sf::VideoMode desktop;
sf::Event event;
tgui::Callback callback;
tgui::Gui gui;
sf::Texture mainMenuBackGround;

tgui::Theme::Ptr theme;
tgui::Layout windowWidth;
tgui::Layout windowHeight;
string mainPanelName;

void setThemeConfigFile(string passed_filename);
void initBackGroundTextures();
void initMainMenuPanel(sf::Vector2i pos, sf::Vector2i size);
void setupPanel(sf::Vector2i pos, sf::Vector2i size, sf::Color passed_backGroundColour, string passed_panelName, sf::Texture *passed_texture = NULL);
void setupLabel(sf::Vector2i pos, int passed_TextSize, sf::Color passed_colour, string labelText, tgui::Container::Ptr container = NULL);
void setupRadioButton(sf::Vector2i pos, sf::Vector2i size, sf::Color passed_colour, vector<string> stringList, tgui::Container::Ptr container = NULL);
bool drawLoadingScreenGUI();
bool drawMainMenuGUI(bool mainMenu); //main menu
};

Test::Test()
{
desktop = sf::VideoMode::getDesktopMode();
gameWindow.create(sf::VideoMode(desktop.width, desktop.height, desktop.bitsPerPixel), "Test");
gameWindow.setPosition(sf::Vector2i(0, 0));
gui.setWindow(gameWindow);
gui.setGlobalFont("C:\\Programming\\Debug\\inputfiles\\fonts\\DejaVuSans.ttf");
initBackGroundTextures();
setThemeConfigFile(THEME_CONFIG_FILE);
mainPanelName = "mainPanel";
}

void Test::setThemeConfigFile(string passed_filename)
{
// Load the black theme
theme = std::make_shared<tgui::Theme>(passed_filename);

// Get a bound version of the window size
// Passing this to setPosition or setSize will make the widget automatically update when the view of the gui changes
windowWidth = tgui::bindWidth(gui);
windowHeight = tgui::bindHeight(gui);
}

void Test::initBackGroundTextures()
{
if (!mainMenuBackGround.loadFromFile("C:\\Users\\mcgoldrickb\\Documents\\Visual Studio 2013\\Projects\\rome_vs2013\\Debug\\images\\loading_screen.png"))
{
std::cout << "Failed to load mainMenuBackGround image!" << std::endl;
}
}

void Test::initMainMenuPanel(sf::Vector2i pos, sf::Vector2i size)
{
setupPanel(pos, size, sf::Color::Black, mainPanelName, &mainMenuBackGround);
}

void Test::setupPanel(sf::Vector2i pos, sf::Vector2i size, sf::Color passed_backGroundColour, string passed_panelName, sf::Texture *passed_texture)
{

if (gui.get(passed_panelName) == NULL)
{
auto mainMenuPanel = std::make_shared<tgui::Panel>();
mainMenuPanel->setPosition(pos.x, pos.y);
mainMenuPanel->setSize(size.x, size.y);
mainMenuPanel->setBackgroundColor(passed_backGroundColour);
if (passed_texture != NULL)
{
mainMenuPanel->add(std::make_shared<tgui::Picture>(*passed_texture));
//mainMenuPanel->getRenderer()->setBackgroundTexture(passed_texture);
}
gui.add(mainMenuPanel, passed_panelName);
}
}

void Test::setupLabel(sf::Vector2i pos, int passed_TextSize, sf::Color passed_colour, string labelText, tgui::Container::Ptr container)
{
if (container->get(labelText) == NULL)
{
tgui::Label::Ptr label = theme->load("Label");
container->add(label, labelText);
label->setPosition(pos.x, pos.y);
label->setTextSize(passed_TextSize);
label->setTextColor(passed_colour);
label->setText(labelText);
}
}

void Test::setupRadioButton(sf::Vector2i pos, sf::Vector2i size, sf::Color passed_colour, vector<string> stringList, tgui::Container::Ptr container)
{
int yposIncrementer = 0;

for (int i = 0; i < stringList.size(); i++)
{
if (container != NULL && container->get(stringList[i]) == NULL)
{
tgui::RadioButton::Ptr radioButton = theme->load("RadioButton");
radioButton->setPosition(pos.x, pos.y + yposIncrementer);
radioButton->setSize(size.x, size.y);
radioButton->getRenderer()->setTextColor(passed_colour);
if (stringList.size() > 0)
{
radioButton->setText(stringList[i]);
}
container->add(radioButton, stringList[i]);
yposIncrementer += size.y;
}
}
}

bool Test::drawLoadingScreenGUI()
{
sf::Vector2i pos, size((gameWindow.getSize().x), (gameWindow.getSize().y));
initMainMenuPanel(pos, size);

//Setup LoadingScreen Label
setupLabel(pos, 100, sf::Color::Red, "Roman Empire", gui.get<tgui::Container>(mainPanelName));


//This is the main menu instructions Label
pos.x = 25;
pos.y = gui.get(mainPanelName)->getSize().y - 100;
setupLabel(pos, 50, sf::Color::Red, "Loading game...", gui.get<tgui::Container>(mainPanelName));


gameWindow.clear();
gui.draw();
gameWindow.display();

return true;
}

bool Test::drawMainMenuGUI(bool mainMenu)
{
vector<string> widgetStrList;

//Initialize the main menu panel
sf::Vector2i pos, size((gameWindow.getSize().x), (gameWindow.getSize().y));
setupPanel(pos, size, sf::Color::Black, mainPanelName, &mainMenuBackGround);
sf::Vector2i panelSize(gui.get(mainPanelName)->getSize().x, gui.get(mainPanelName)->getSize().y);


//This is the main menu Title
pos.x = 25;
pos.y = 50;
setupLabel(pos, 100, sf::Color::Red, "Roman Empire - Main Menu", gui.get<tgui::Container>(mainPanelName));



//Setup Main Menu Radio Buttons
pos.y = 50 + 70;
size.x = 35;
size.y = 35;

widgetStrList.push_back("\tQuit Game");
widgetStrList.push_back("\tStart New Game");
widgetStrList.push_back("\tLoad Old Game");

if (mainMenu == true)
{
setupRadioButton(pos, size, sf::Color::Red, widgetStrList, gui.get<tgui::Container>(mainPanelName));
}
else if (mainMenu == false)
{
widgetStrList.push_back("\tSave Current Game");
widgetStrList.push_back("\tExit Main Menu");
setupRadioButton(pos, size, sf::Color::Red, widgetStrList, gui.get<tgui::Container>(mainPanelName));
}

widgetStrList.clear();

gameWindow.clear();

gui.draw();
gameWindow.display();
return true;
}


texus

#1
The code worked for me (although I don't have the exact code since you didn't include the main function, I just created a Test instance and called drawMainMenu on it).

But if I google the error then it seems like a linking problem that causes it to crash on runtime. So based on what I have read it should have something to do with one of those things:
In Visual Studio, did you change any settings about Runtime Library (stuff like /MD, /MT, /MDd or /MTd)? Don't touch these options unless you recompile sfml and tgui for the non-default setting.
If you compiled TGUI, did you keep TGUI_USE_STATIC_STD_LIBS unchecked? Because it should only be checked when you fully understand what it does.
Did you download the v0.7-alpha version for VS2013? If so, are you using the official SFML 2.3.1 VS2013 libraries as well?
You are sure that you are not accidentally linking release libraries in debug mode?

starkhorn

sorry - yeah I was using the Visual C++ 11 (2012) - 32-bit sfml 2.3.1 dll files and not the Visual C++ 12 (2013) - 32-bit files.

Thanks again.