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.


Topics - BiiXteR

Pages: [1]
1
I'm having a problem where sf::Event::type is by "default" (as soon as the window opens) equal to sf::Event::Closed, which results in as soon as the window opening, it runs trough the game loop once and then exits the game.

My game loop looks like this :

        while (InputManager::CloseEventDetected() == false)
        {
                m_displayMgr->PollWindowEvents(*InputManager::GetEventClass());
                InputManager::HandleInput();

                m_displayMgr->GetRenderWindow()->draw(*m_levelMgr);
                m_displayMgr->Render();

                std::cout << "Closed evnt : " << InputManager::CloseEventDetected() << std::endl;
        }
 

And my InputManager header file looks like this :
#pragma once
#include <SFML\Graphics.hpp>

class InputManager
{
public:

        static void HandleInput();

        static bool IsKeyDown(sf::Keyboard::Key key);
        static bool isKeyDownRepeat(sf::Keyboard::Key key);

        static bool IsKeyUp(sf::Keyboard::Key key);
        static bool IsKeyUpRepeat(sf::Keyboard::Key key);

        static bool CloseEventDetected();

        static sf::Event* GetEventClass();

private:

        InputManager();

        static bool m_keys[sf::Keyboard::KeyCount];
        static bool m_keysLastFrame[sf::Keyboard::KeyCount];

        static bool m_closeEventDetected;

        static sf::Event* m_evnt;
};
 

And the cpp file looks like this :
#include "InputManager.h"

bool InputManager::m_keys[sf::Keyboard::KeyCount];
bool InputManager::m_keysLastFrame[sf::Keyboard::KeyCount];

bool InputManager::m_closeEventDetected = false;

sf::Event* InputManager::m_evnt = new sf::Event();

InputManager::InputManager()
{
        m_evnt = new sf::Event();
}

void InputManager::HandleInput()
{
        for (int i = 0; i < sf::Keyboard::KeyCount; i++)
        {
                m_keys[i] = (sf::Keyboard::isKeyPressed((sf::Keyboard::Key)i));

                m_keysLastFrame[i] = m_keys[i];
        }

        if (m_evnt->type == sf::Event::Closed)
        {
                printf("close detect");
                m_closeEventDetected = true;
        }

}

bool InputManager::IsKeyDown(sf::Keyboard::Key key)
{
        if (m_keys[key] == true && m_keysLastFrame[key] != true)
        {
                return true;
        }
        else
        {
                return false;
        }
}

bool InputManager::isKeyDownRepeat(sf::Keyboard::Key key)
{
        return m_keys[key];
}

bool InputManager::IsKeyUp(sf::Keyboard::Key key)
{
        if (m_keys[key] == true && m_keysLastFrame[key] != true) //TODO: Not sure if it works.
        {
                return false;
        }
        else
        {
                return true;
        }
}

bool InputManager::CloseEventDetected()
{
        return m_closeEventDetected;
}

sf::Event* InputManager::GetEventClass()
{
        return m_evnt;
}

bool InputManager::IsKeyUpRepeat(sf::Keyboard::Key key)
{
        return !m_keys[key];
}
 

Basically what happens is :

The window is created, and the game loop runs trough correctly once, but on the second loop InputManager::CloseEventDetected() returns true which results in the game loop breaking and the game closing.

But I can't seem to find any reason to why the sf::Event::type would be equal to Sf::Event::Closed.

2
General / Cannot find cause of ntdll.dll crash in application
« on: February 20, 2017, 12:44:01 pm »
Today I've been trying to implement a in-game console system for my game, I was just giving it a rectangle background, but when I ran the game it crashes as soon as I pressed F12 to open the console, and gave me ther error :

UntitledCppGame.exe has triggered a breakpoint.

When pressing the "break" button I was greeted by this page in visual studio :



And that is all information that Visual Studio gives me about the crash, and I have no idea at all how to find out what's causing it.

Here's the head and cpp file for the Console system :

Header :
#pragma once

#include "Input.h"
#include "BoxSprite.h"

class Console
{

public:

        Console();
        ~Console();

        void Initialize();

        void OpenConsole();
        void CloseConsole();

        void Draw();
        void Update();
        void HandleEvents();

        bool IsConsoleOpen();

        void PrintMessage(std::string file, std::string msg);
        void PrintWarning(std::string file, std::string msg);
        void PrintError(std::string file, std::string msg);
        void PrintFatal(std::string file, std::string msg);

private:

        const int M_CONSOLE_OPEN_BIND = sf::Keyboard::F12;

        bool m_isConsoleOpen;
        bool m_isConsoleReady = false;

        BoxSprite m_consoleRect;

};
 

Source :
#include "Console.h"

#include "Globals.h"

Console gConsole;

Console::Console()
{

}

Console::~Console()
{
}

void Console::Initialize()
{
        m_consoleRect = BoxSprite(Vector2(gGraphics.GetWindow().getSize().x, gGraphics.GetWindow().getSize().y / 3), Vector2(0, 0), Color::White);

        m_isConsoleReady = true;
}

void Console::Draw()
{
        if (m_isConsoleOpen == true)
        {
                m_consoleRect.Draw();
        }
}

void Console::Update()
{
       
}

void Console::HandleEvents()
{
       
        if (gInput.isKeyDown(M_CONSOLE_OPEN_BIND))
        {
                if (IsConsoleOpen() == true)
                {
                        CloseConsole();
                }
                else
                {
                        OpenConsole();
                }
        }

}

bool Console::IsConsoleOpen()
{
        return m_isConsoleOpen;
}

void Console::OpenConsole()
{

}

void Console::CloseConsole()
{

}

void Console::PrintMessage(std::string file, std::string msg)
{

}

void Console::PrintWarning(std::string file, std::string msg)
{

}

void Console::PrintError(std::string file, std::string msg)
{

}

void Console::PrintFatal(std::string file, std::string msg)
{

}
 

3
General / Debug Assertion when using 'Texture.update(sf::Window)'
« on: December 02, 2016, 06:46:59 pm »
So, I'm trying to update my texture but when I do that my game triggers a assertion which tells me :
Assertion failed: x + window.getSize().x <= m_size.x, file (long path)\Texture.cpp

In my code, this line triggers the assertion :
gResourceMgr.GetTexture(textureName)->update(gGraphics.GetWindow());

GetTexture() is this :
sf::Texture* ResourceManager::GetTexture(std::string file)
{
        if (textures.find(file) != textures.end())
        {
                return textures.find(file)->second;
        }
        else
        {
                std::cout << "Failed to get file : " << file << " from resource manager." << std::endl;
                return nullptr;
        }
}

And the textures map looks like this :
std::map<std::string, sf::Texture*> textures;

The gGraphics.GetWindow() function simply returns a reference to the games RenderWindow.

Unsure what I'm doing wrong :/

4
(Note, this is a TGUI / C++ question, not sure if this is where I should post it.)

I'm trying to do this :


void GUIManager::CreateButton(std::string m_identifier, std::string m_buttonText, std::string m_fontPath, void* func, float m_xPos, float m_yPos, float m_width, float m_height)
{
       
        tgui::Button::Ptr m__temp_btn = std::make_shared<tgui::Button>();

        m__temp_btn->setFont(m_fontPath);
        m__temp_btn->setText(m_buttonText);
        m__temp_btn->setPosition(m_xPos, m_yPos);
        m__temp_btn->setSize(m_width, m_height);

        _buttonList.insert(std::make_pair(m_identifier, m__temp_btn));

        _buttonList[m_identifier]->connect("pressed", func); // It's because of this func parameter I get the error,

        _gui.add(_buttonList[m_identifier]);

}

 

Which TGUi doesn't want me to since it gives me this error :

Error   C2893   Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...)'   
 

What am I doing wrong? :/

(I think this should be enough code to reproduce the error)

5
General / Trying to read the value of a sf::String causes crash
« on: August 16, 2016, 11:22:25 pm »
(Note : I'm still a beginner when it comes to programming, so sorry if it's something obvious)

So, when I try to print out the value of one of my function arguments of the type sf::String my entire application crashes with the error message ;

Quote
Exception thrown at 0x0FDE6D16 (msvcp140d.dll) in SwEngine.exe: 0xC0000005: Access violation reading location 0xCCCCCCCC.

If there is a handler for this exception, the program may be safely continued.

I believe  that a conversion between a std::String (which I send in to the function parameter of the type sf::String) fails, which leads to a crash, because when i try to use this sf::String value as a window title, the title is blank.

Here's some code :

This is the function which contains the sf::String value, and here's where the program crashes.

void Window::Create(unsigned int width, unsigned int height, sf::String title)
{

        std::cout << title.toAnsiString() << std::endl; // Crashes here.

}
 

And here's how I call that function :

Window::GetInstance().Create(1024, 720, globals::GAME_NAME);

And this is what the GAME_NAME variable is :

namespace globals
{

        // The name of the game the engine is currently running.
        const std::string GAME_NAME = "SwEngine Testing";

}
 

I'm pretty confused since it says in the SFML page that it handles conversions between the 2 string automatically, so, am I doing something very wrong here? :o

6
Graphics / [SOLVED] - sf::Sprite is not a drawable?
« on: January 11, 2016, 06:58:54 pm »
So, currently I have this :


std::map<std::string, sf::Sprite*> sprites;


and I loop trough it like this :
        for (auto const& i : sprites)
        {
                window->draw(i.second);
        }
 
But when I try to run it, it tells me that :

illegal indirection
 void sf::RenderTarget::draw(const sf::Vertex *,size_t,sf::PrimitiveType,const sf::RenderStates &)': cannot convert argument 1 from 'sf::Sprite *const ' to 'const sf::Drawable &

Reason: cannot convert from 'sf::Sprite *const ' to 'const sf::Drawable'
No constructor could take the source type, or constructor overload resolution was ambiguous



Note :
I'm pretty new to both C++ and SFML so it might be obvious.
It might not even be a SFML problem.
 :P

Pages: [1]
anything