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

Pages: [1]
1
General / Re: sf::Text application crash
« on: June 18, 2020, 08:55:56 pm »
Many thanks!

The specification is very clear, indeed.

I tought that the text object would store a copy of the font, that seemed intuitive to me, for the convenience of not having to manage a separate object, and it would prevent the application crash, that in VS debugs into a misterious "Access violation reading location".
Exception thrown at 0x00007FF6020939E3 in Example.exe: 0xC0000005: Access violation reading location 0x0000000000000008.
In general, I worry about these "Access violation" problems, wondering if they could be a security concern (exploitable). Of course, they depend on a bug in the code, as always... in my case, to let the font object get out of scope. But the point is if that bug is a fairly common mistake, then we have a risk.

Anyway, I understand that was a design choice, and I'm sure for good reasons (memory... if one font and many texts; perhaps performance also for the copy).

2
General / [SOLVED] sf::Text application crash
« on: June 18, 2020, 05:07:19 pm »
Hi,

Little help please...

The following simple example shows a reproducible crash with no compiler warnings.

1/ Example.cpp

#include <SFML/Graphics.hpp>
#include "MyClass.h"

int main()
{
    // create a graphical text
    sf::Font font;
    font.loadFromFile("c:\\windows\\fonts\\arial.ttf");
    sf::Text txt("sample text", font, 24);

    // create a MyClass object
    MyClass myObject;

    sf::RenderWindow window(sf::VideoMode(800, 600), "");
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }
        window.clear();
       
        window.draw(txt);                   // this works fine (if we comment out the next line)
        window.draw(myObject.objectText);   // this crashes application!
       
        window.display();
    }
}

2/ MyClass.h

#pragma once
#include <SFML/Graphics.hpp>

class MyClass
{
public:
        MyClass();
        sf::Text objectText;
};

3/ MyClass.cpp

#include "MyClass.h"

MyClass::MyClass()
{
        sf::Font font;
        font.loadFromFile("c:\\windows\\fonts\\arial.ttf");
        objectText.setFont(font);
        objectText.setString("object text");
        objectText.setCharacterSize(24);
        objectText.setPosition(25, 50);
}

Environment is VS 16.6.2 (latest), x64, SFML 2.5.1, Preprocessor SFML_STATIC, additional dependencies sfml-main.lib;sfml-graphics-s.lib;sfml-window-s.lib;sfml-system-s.lib;opengl32.lib;winmm.lib;freetype.lib;

I'm a bit fuzzy why this crashes... can you help?
Thanks!

Pages: [1]
anything