1
Graphics / Re: Crash after using sf::Text
« on: January 27, 2020, 11:12:04 pm »
I've changed my code and now the problem is so weird...
I want to draw four sf::Text - crash.
I want to draw one sf::Text - it's ok.
Debugger shows error in line: window.draw(num2);
Debugger:
Actual code:
Settings.h:
Settings.cpp (method I use):
I want to draw four sf::Text - crash.
I want to draw one sf::Text - it's ok.
Debugger shows error in line: window.draw(num2);
Debugger:
Actual code:
Settings.h:
#pragma once
#include "ConstState.h"
#include <SFML/Graphics.hpp>
#include <array>
class Settings
{
public:
Settings();
void runSettings(sf::RenderWindow& window, ConstState& state);
void moveUp();
void moveDown();
private:
sf::Font* lucidra;
sf::Text num1;
sf::Text num2;
sf::Text num3;
sf::Text num4;
void drawSettings(sf::RenderWindow& window);
sf::Texture settingsT;
sf::Sprite settingsS;
int getCursor();
std::array<sf::RectangleShape, 4> settings;
int cursor;
int countX;
int countY;
float ballV;
float paddleV;
};
#include "ConstState.h"
#include <SFML/Graphics.hpp>
#include <array>
class Settings
{
public:
Settings();
void runSettings(sf::RenderWindow& window, ConstState& state);
void moveUp();
void moveDown();
private:
sf::Font* lucidra;
sf::Text num1;
sf::Text num2;
sf::Text num3;
sf::Text num4;
void drawSettings(sf::RenderWindow& window);
sf::Texture settingsT;
sf::Sprite settingsS;
int getCursor();
std::array<sf::RectangleShape, 4> settings;
int cursor;
int countX;
int countY;
float ballV;
float paddleV;
};
Settings.cpp (method I use):
void Settings::drawSettings(sf::RenderWindow& window)
{
lucidra = new sf::Font;
if (!(*lucidra).loadFromFile("res\\Lucida Fax Demibold.ttf"))
std::cout << "error!!!!";
num1.setFont(*lucidra);
num1.setCharacterSize(40);
num1.setFillColor(sf::Color::Color(0, 234, 235));
num1.setString(std::to_string(countX));
num1.setPosition(sf::Vector2f(320.f, 311.f));
num2.setFont(*lucidra);
num2.setCharacterSize(40);
num2.setFillColor(sf::Color::Color(0, 234, 235));
num2.setString(std::to_string(countY));
num2.setPosition(sf::Vector2f(320.f, 374.f));
num3.setFont(*lucidra);
num3.setCharacterSize(40);
num3.setFillColor(sf::Color::Color(0, 234, 235));
num3.setString(std::to_string(ballV));
num3.setPosition(sf::Vector2f(320.f, 448.f));
num4.setFont(*lucidra);
num4.setCharacterSize(40);
num4.setFillColor(sf::Color::Color(0, 234, 235));
num4.setString(std::to_string(paddleV));
num4.setPosition(sf::Vector2f(320.f, 516.f));
window.clear();
window.draw(settingsS);
window.draw(num1);
window.draw(num2);
window.draw(num3);
window.draw(num4);
for (int i=0;i<=3;i++)
{
window.draw(settings.at(i));
}
}
{
lucidra = new sf::Font;
if (!(*lucidra).loadFromFile("res\\Lucida Fax Demibold.ttf"))
std::cout << "error!!!!";
num1.setFont(*lucidra);
num1.setCharacterSize(40);
num1.setFillColor(sf::Color::Color(0, 234, 235));
num1.setString(std::to_string(countX));
num1.setPosition(sf::Vector2f(320.f, 311.f));
num2.setFont(*lucidra);
num2.setCharacterSize(40);
num2.setFillColor(sf::Color::Color(0, 234, 235));
num2.setString(std::to_string(countY));
num2.setPosition(sf::Vector2f(320.f, 374.f));
num3.setFont(*lucidra);
num3.setCharacterSize(40);
num3.setFillColor(sf::Color::Color(0, 234, 235));
num3.setString(std::to_string(ballV));
num3.setPosition(sf::Vector2f(320.f, 448.f));
num4.setFont(*lucidra);
num4.setCharacterSize(40);
num4.setFillColor(sf::Color::Color(0, 234, 235));
num4.setString(std::to_string(paddleV));
num4.setPosition(sf::Vector2f(320.f, 516.f));
window.clear();
window.draw(settingsS);
window.draw(num1);
window.draw(num2);
window.draw(num3);
window.draw(num4);
for (int i=0;i<=3;i++)
{
window.draw(settings.at(i));
}
}