Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - xorioz

Pages: [1]
1
Graphics / Re: Font loading problem (Crash)
« on: March 21, 2014, 03:46:01 pm »
Quote
I'm using clang 3.4 on Linux and I'm very happy with it and its C++11 support.

Yep. was actually just looking over the 11 support of clang and i'm impressed.

Now i just have to make it work with my IDE :)
If i cant figure that out ill use the MinGW version eXploiter recomended.
Atleast i know how to set it up :)

2
Graphics / Re: Font loading problem (Crash)
« on: March 21, 2014, 03:01:28 pm »
ok...Note to self. "and other noobs"
Dont use the newest version of MinGW.
It craps all over SFML...

Can anyone recomend a good c++1.1 compiler.

3
Graphics / Re: Font loading problem (Crash)
« on: March 21, 2014, 02:17:24 pm »
oh well.
I'm not good at doing nothing so i'm gonna delete all sfml libraries on my computer.
Remove mingw and grab a new one.
set mingw up from scratch making sure all my environment vars are set properly.
Redownload SFML 2.1 source.
use cmake and my newly acquired mingw to compile SFML and then set up my project from scratch.
hoping this will fix my problem or at least rule out any linker or dependency problems.

4
Graphics / Re: Font loading problem (Crash)
« on: March 20, 2014, 03:08:11 pm »
On a side note i found another "obvious" flaw in my programming.
void Game::calculateFPS(sf::Time deltaTime)
{
    FPS++;
    if(deltaTime >= FPSTime)
    {
        std::stringstream ss;
        ss << FPS;
        showStr = baseStr + ss.str();
        mText.setString(showStr);
        FPS = 0;
        deltaTime = sf::seconds(0.0f);
    }
}
 

notice how i set deltaTime to 0 if it's over 1
This does not do a thing as the sf::Time a pass to the function isn't changed :)
So this makes the FPS text update every frame instead of every second and it just prints out FPS: 1.

I'm using cout until i can get the font loading fixed.

5
Graphics / Re: Font loading problem (Crash)
« on: March 20, 2014, 08:08:44 am »
oh. and just to be safe i moved all class member initialization to the constructor in Game.cpp and removed all semicolons after closing brackets :)

6
Graphics / Re: Font loading problem (Crash)
« on: March 20, 2014, 07:47:51 am »
so after running the debugger i get this.
Error while reading shared library symbols for C:\Program Files (x86)\CodeBlocks\MinGW\bin\libstdc++-6.dll:
Program received signal SIGSEGV, Segmentation fault.
At c:\progra~2\codebl~1\mingw\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_algobase.h:697

I also have this in my call stack.
#0 68F8351B   std::__fill_a<unsigned char>(__first=0x0, __last=0x344 <Address 0x344 out of bounds>, __c=@0x28f33f: 255 '\377') (c:/progra~2/codebl~1/mingw/bin/../lib/gcc/mingw32/4.7.1/include/c++/bits/stl_algobase.h:697)
#1 68F82404   std::__fill_n_a<unsigned int, unsigned char>(__first=0x0, __n=836, __c=@0x28f33f: 255 '\377') (c:/progra~2/codebl~1/mingw/bin/../lib/gcc/mingw32/4.7.1/include/c++/bits/stl_algobase.h:754)
#2 68F8333F   std::fill_n<unsigned char*, unsigned int, unsigned char>(__first=0x0, __n=836, __value=@0x28f33f: 255 '\377') (c:/progra~2/codebl~1/mingw/bin/../lib/gcc/mingw32/4.7.1/include/c++/bits/stl_algobase.h:780)
#3 68F7AB37   std::__uninitialized_fill_n<true>::__uninit_fill_n<unsigned char*, unsigned int, unsigned char>(__first=0x0, __n=836, __x=@0x28f33f: 255 '\377') (c:/progra~2/codebl~1/mingw/bin/../lib/gcc/mingw32/4.7.1/include/c++/bits/stl_uninitialized.h:206)
#4 68F82933   std::uninitialized_fill_n<unsigned char*, unsigned int, unsigned char>(__first=0x0, __n=836, __x=@0x28f33f: 255 '\377') (c:/progra~2/codebl~1/mingw/bin/../lib/gcc/mingw32/4.7.1/include/c++/bits/stl_uninitialized.h:225)
#5 68F82D7B   std::__uninitialized_fill_n_a<unsigned char*, unsigned int, unsigned char, unsigned char>(__first=0x0, __n=836, __x=@0x28f33f: 255 '\377') (c:/progra~2/codebl~1/mingw/bin/../lib/gcc/mingw32/4.7.1/include/c++/bits/stl_uninitialized.h:336)
#6 68F7DE4B   std::vector<unsigned char, std::allocator<unsigned char> >::_M_fill_insert(this=0x28fe14, __position=..., __n=836, __x=@0x28f3c8: 255 '\377') (c:/progra~2/codebl~1/mingw/bin/../lib/gcc/mingw32/4.7.1/include/c++/bits/vector.tcc:464)
#7 68F7E2FB   std::vector<unsigned char, std::allocator<unsigned char> >::insert(this=0x28fe14, __position=..., __n=836, __x=@0x28f3c8: 255 '\377') (c:/progra~2/codebl~1/mingw/bin/../lib/gcc/mingw32/4.7.1/include/c++/bits/stl_vector.h:1004)
#8 68F7E35B   std::vector<unsigned char, std::allocator<unsigned char> >::resize(this=0x28fe14, __new_size=836, __x=255 '\377') (c:/progra~2/codebl~1/mingw/bin/../lib/gcc/mingw32/4.7.1/include/c++/bits/stl_vector.h:687)
#9 68EC2E66   sf::Font::loadGlyph(this=0x28fde8, codePoint=70, characterSize=30, bold=false) (D:\Projects\SFML-master\src\SFML\Graphics\Font.cpp:467)
#10 68EC26AC   sf::Font::getGlyph(this=0x28fde8, codePoint=70, characterSize=30, bold=false) (D:\Projects\SFML-master\src\SFML\Graphics\Font.cpp:282)
#11 68EDFCCB   sf::Text::updateGeometry(this=0x28fe1c) (D:\Projects\SFML-master\src\SFML\Graphics\Text.cpp:303)
#12 68EDEFBF   sf::Text::setFont(this=0x28fe1c, font=...) (D:\Projects\SFML-master\src\SFML\Graphics\Text.cpp:78)
#13 00401839   Game::Game(this=0x28fab0) (D:\Projects\C++\Engine base\Game.cpp:23)
#14 00402480   main() (D:\Projects\C++\Engine base\main.cpp:5)


don't know if that helps at all :)

7
Graphics / Re: Font loading problem (Crash)
« on: March 19, 2014, 06:01:55 pm »
W8 now i'm confused.
I'm compiling just fine with the code as is. using Dynamic linked libraries.
Are you sure you are compiling with the newest mingw/gcc compiler with c++ 1.1 enabled?
And according to the link FRex wrote i can initialize my members in the header just fine "c++ 1.1".
If it's good coding practice is a whole other matter.

I'm getting some stuff out of the debugger in C::B and it looks like the error might have something to do with another library that SFML depends upon.

Oh well i'm about to go to bed atm so I will post some debugging info tomorrow.

8
Graphics / Re: Font loading problem (Crash)
« on: March 19, 2014, 03:34:57 pm »
well the class Game is declared in Game.h witch in turn is included in main.cpp where i initialize the class as the object game and execute the run function of the class
#include "Game.h"

int main()
{
    Game game;
    game.run();
}
 

Vary simple.

I can do a full code paste here. might help.

main.cpp
#include "Game.h"

int main()
{
    Game game;
    game.run();
}
 

Game.h
#ifndef GAME_H_INCLUDED
#define GAME_H_INCLUDED

#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
#include <sstream>

class Game
{
public:
    Game();
    void run();
private:
    void calculateFPS(sf::Time deltaTime);
    void handlePlayerInput(sf::Keyboard::Key key, bool isPressed);
    void processEvents();
    void update(sf::Time deltaTime);
    void render();
private:
    bool mIsMovingUp = false, mIsMovingDown = false, mIsMovingLeft = false, mIsMovingRight = false;
    float mPlayerSpeed = 100.0f;
    sf::Time mTimePerFrame = sf::seconds(1.0f / 60.0f), returnTime = sf::seconds(0.0f), FPSTime = sf::seconds(1.0f);
    sf::RenderWindow mWindow;
    sf::Texture mTexture;
    sf::Sprite mPlayer;
    sf::Font mFont;
    sf::Text mText;
    int FPS = 0;
    std::string baseStr = "FPS: ", showStr;
};

#endif // GAME_H_INCLUDED
 

Game.cpp
#include "Game.h"

Game::Game()
    : mWindow(sf::VideoMode(640, 480), "SFML Application")
    , mPlayer()
    , mTexture()
    , mFont()
    , mText()
{
    if (!mFont.loadFromFile("consola.ttf"))
    {
       /* Handle loading error */
    };

    if (!mTexture.loadFromFile("dot.png"))
    {
        /* Handle loading error */
    }

    mPlayer.setTexture(mTexture);
    mPlayer.setPosition(100.f, 100.f);
    mText.setString("FPS: 0");
    mText.setFont(mFont);
    mText.setCharacterSize(12);
    mText.setColor(sf::Color::Black);
    mText.setStyle(sf::Text::Bold);
}
void Game::run()
{
    sf::Clock clock;
    sf::Clock frameTimer;
    sf::Time timeSinceLastUpdate = sf::Time::Zero;
    while (mWindow.isOpen())
    {
        returnTime += frameTimer.restart();
        calculateFPS(returnTime);
        processEvents();
        timeSinceLastUpdate += clock.restart();
        while (timeSinceLastUpdate > mTimePerFrame)
        {
            timeSinceLastUpdate -= mTimePerFrame;
            processEvents();
            update(mTimePerFrame);
        }
        render();
    }
}

void Game::calculateFPS(sf::Time deltaTime)
{
    FPS++;
    if(deltaTime >= FPSTime)
    {
        std::stringstream ss;
        ss << FPS;
        showStr = baseStr + ss.str();
        mText.setString(showStr);
        FPS = 0;
        deltaTime = sf::seconds(0.0f);
    }
}

void Game::handlePlayerInput(sf::Keyboard::Key key, bool isPressed)
{
    if (key == sf::Keyboard::W)
        mIsMovingUp = isPressed;
    else if (key == sf::Keyboard::S)
        mIsMovingDown = isPressed;
    else if (key == sf::Keyboard::A)
        mIsMovingLeft = isPressed;
    else if (key == sf::Keyboard::D)
        mIsMovingRight = isPressed;
}

void Game::processEvents()
{
    sf::Event event;
    while (mWindow.pollEvent(event))
    {
        switch (event.type)
        {
        case sf::Event::KeyPressed:
            handlePlayerInput(event.key.code, true);
            break;
        case sf::Event::KeyReleased:
            handlePlayerInput(event.key.code, false);
            break;
        case sf::Event::Closed:
            mWindow.close();
            break;
        }
    }
}

void Game::update(sf::Time deltaTime)
{
    sf::Vector2f movement(0.f, 0.f);
    if (mIsMovingUp)
        movement.y -= mPlayerSpeed;
    if (mIsMovingDown)
        movement.y += mPlayerSpeed;
    if (mIsMovingLeft)
        movement.x -= mPlayerSpeed;
    if (mIsMovingRight)
        movement.x += mPlayerSpeed;
    mPlayer.move(movement * deltaTime.asSeconds());
}

void Game::render()
{
    mWindow.clear(sf::Color::White);
    mWindow.draw(mPlayer);
    mWindow.display();
}
 

Well i know the code is not perfect. but i'm still learning proper coding practices so bare with me :)
PS. using SFML 2.1

9
Graphics / Font loading problem (Crash)
« on: March 19, 2014, 03:10:23 pm »
So. I'm fairly new to SFML and still learning c++.
And i'm curently in the process of making a simple Frame counter "FPS".
But i have run into a problem with Font loading.
When i do an ultra simple code like this.

    // some text stuff
    sf::Font font;
    if (!font.loadFromFile("consola.ttf"))
    {
        // error...
    }
    sf::Text text;
    text.setString("FPS: 0");
    text.setFont(font);
    text.setCharacterSize(12);
    text.setColor(sf::Color::Black);
    text.setStyle(sf::Text::Bold);
 

the program functions just fine.
But when i start to work with classes the program crashes at startup

Game.h
class Game
{
public:
    Game();
    void run();
private:
    ...
private:
    ...
    sf::Font mFont;
    sf::Text mText;
};
 

Game.cpp
Game::Game() : mWindow(sf::VideoMode(640, 480), "SFML Application"), mFont(), mText()
{
    if (!mFont.loadFromFile("consola.ttf"))
    {
       /* Handle loading error */
    };

    mText.setString("FPS: 0");
    mText.setFont(mFont);
    mText.setCharacterSize(12);
    mText.setColor(sf::Color::Black);
    mText.setStyle(sf::Text::Bold);
}
 

Now i think it has something to do with the font as the problem persists in all cases except when i comment out mText.setFont(mFont);
I have tried other fonts including Times New Roman.

I'm currently reading up on debugging in code::blocks but i'm not getting anywhere.
If anyone can give a helping hand i would appreciate it a lot.

Thinks XorioZ

Pages: [1]