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 - supernintendo64

Pages: [1]
1
General / "Unknown CMake command 'build_chapter'"
« on: February 06, 2022, 05:42:18 pm »
I'm trying to compile the example project files that came with the SFML Game Development book (the one with the ocean and rock on the cover). I'm using Visual Studio 2022. I went to "Open CMake" and ran the CMakeLists that was in the project directory and got an error on Line 6:

Code: [Select]
CMake Error at G:\[Name]\Documents\Packt\SFML Game Development\01_Intro\Source\CMakeLists.txt:6 (build_chapter): Unknown CMake command "build_chapter".

What am I doing wrong?

2
Graphics / Re: Exception when trying to draw text from a function
« on: May 04, 2019, 11:44:33 pm »
You're passing in a copy of the font (which will go out of scope when the function returns) instead of a reference. Resources such as fonts, textures and sound buffers need to make sure their lifetime exceeds that of anything which uses them. Usually this is done with some sort of resource manager, examples of which are on the wiki, or available in libraries like Thor.

Thank you so much. I changed the function so that the variable font is being referenced instead of being copied (i.e. I changed sf::Font font to sf::Font &font) and it fixed the problem.

3
Graphics / Exception when trying to draw text from a function
« on: May 04, 2019, 08:07:18 pm »
Hi,

So I'm trying to get started on a new game. I figured that I could streamline the action of rendering text by putting all of the routines needed to do it (setting the font, the size, the color, and the text itself) into a function but when I try to execute this function, I get the error "Exception thrown at 0x0FD2485F (sfml-graphics-d-2.dll) in SFMLProject.exe: 0xC0000005: Access violation reading location 0x3F800004."

Here is my code:

#include <SFML/Graphics.hpp>

sf::Text drawText(sf::Font font, std::string inputText, int size, sf::Color color) //Function to draw text (TODO: Add the ability to specify coordinates)
{
        sf::Text outputText;
        outputText.setFont(font);
        outputText.setString(inputText);
        outputText.setCharacterSize(size);
        outputText.setFillColor(color);
        return outputText;
}

int main()
{
        sf::RenderWindow window(sf::VideoMode(200, 200), "SFML Project");
        sf::CircleShape shape(100.f);
        sf::Font testFont;
        testFont.loadFromFile("calibri.ttf");

        shape.setFillColor(sf::Color::Green);

        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }

                window.clear();
                window.draw(shape);
                window.draw(drawText(testFont, "Development Build 0", 12, sf::Color::White));
                window.display();
        }

        return 0;
}

EDIT: I just want to add that this does not happen when I manually draw text in the main function.

Pages: [1]
anything