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

Pages: [1]
1
Graphics / [SOLVED] Weird error in sf::Font initialization
« on: June 13, 2014, 02:06:34 pm »
Hi, recently my game begin segfaulting with this backtrace
Code: [Select]
Program received signal SIGSEGV, Segmentation fault.
memset () at ../sysdeps/x86_64/memset.S:78
78 ../sysdeps/x86_64/memset.S: No such file or directory.
(gdb) bt
#0  memset () at ../sysdeps/x86_64/memset.S:78
#1  0x00007ffff7994711 in sf::Font::loadGlyph(unsigned int, unsigned int, bool) const () from /usr/local/lib64/libsfml-graphics.so.2
#2  0x00007ffff7994e69 in sf::Font::getGlyph(unsigned int, unsigned int, bool) const () from /usr/local/lib64/libsfml-graphics.so.2
#3  0x00007ffff79b7533 in sf::Text::updateGeometry() () from /usr/local/lib64/libsfml-graphics.so.2
#4  0x00007ffff79b7e83 in sf::Text::Text(sf::String const&, sf::Font const&, unsigned int) () from /usr/local/lib64/libsfml-graphics.so.2
#5  0x0000000000506286 in Computers::Software::Programs::UpperPanel::UpperPanel (this=0x79ac50, os=...) at /home/anrock/Documents/cprl/src/Computers/Software/Programs/UpperPanel.cpp:10
#6  0x00000000005029e4 in Computers::Software::Programs::ProgramFactory::spawn (os=..., id="UpperPanel") at /home/anrock/Documents/cprl/src/Computers/Software/Programs/ProgramFactory.cpp:25
#7  0x00000000004fdf63 in Computers::Software::OperatingSystem::start (this=0x7942a0) at /home/anrock/Documents/cprl/src/Computers/Software/OperatingSystem.cpp:98
#8  0x00000000004f7f51 in Computers::Computer::turnOn (this=0x7fffffffb2a0) at /home/anrock/Documents/cprl/src/Computers/Computer.cpp:44
#9  0x00000000004ec624 in ____C_A_T_C_H____T_E_S_T____14 () at /home/anrock/Documents/cprl/Tests/TestCp.cpp:23
#10 0x00000000004b3396 in Catch::FreeFunctionTestCase::invoke (this=0x74e770) at /home/anrock/Documents/cprl/Tests/catch.hpp:5414
#11 0x00000000004a3a25 in Catch::TestCase::invoke (this=0x74a7d0) at /home/anrock/Documents/cprl/Tests/catch.hpp:6282
#12 0x00000000004b135d in Catch::RunContext::runCurrentTest (this=0x7fffffffddf0, redirectedCout="", redirectedCerr="") at /home/anrock/Documents/cprl/Tests/catch.hpp:5027
#13 0x00000000004b033d in Catch::RunContext::runTest (this=0x7fffffffddf0, testCase=...) at /home/anrock/Documents/cprl/Tests/catch.hpp:4873
#14 0x00000000004b1e2b in Catch::Runner::runTestsForGroup (this=0x7fffffffe010, context=..., filterGroup=...) at /home/anrock/Documents/cprl/Tests/catch.hpp:5164
#15 0x00000000004b1b23 in Catch::Runner::runTests (this=0x7fffffffe010) at /home/anrock/Documents/cprl/Tests/catch.hpp:5145
#16 0x00000000004b2ad0 in Catch::Session::run (this=0x7fffffffe300) at /home/anrock/Documents/cprl/Tests/catch.hpp:5287
#17 0x00000000004b299e in Catch::Session::run (this=0x7fffffffe300, argc=1, argv=0x7fffffffe4c8) at /home/anrock/Documents/cprl/Tests/catch.hpp:5270
#18 0x00000000004a71ba in main (argc=1, argv=0x7fffffffe4c8) at /home/anrock/Documents/cprl/Tests/catch.hpp:8247

Font loaded like this:
        if (!SystemFont.loadFromFile("Resources/Fonts/Terminus.ttf"))
                std::cerr << "Can't load font" << std::endl;
 
No error reported

Then sf::Text field is initialized with this font in another class like this:
username(OS.getUsername(), OS.getFont(), 14)
getUsername() returns std::strings and getFont() returns reference to loaded font.

Now about weirdness i've found.
GDB's "p SystemFont" before SystemFont is initialized looks like this:
SystemFont = {m_library = 0x0, m_face = 0x0, m_streamRec = 0x0, m_refCount = 0x0, m_pages = std::map with 0 elements, m_pixelBuffer = std::vector of length 0, capacity 0}
and after call to loadFromFile:
SystemFont = {m_library = 0x794680, m_face = 0x799cc0, m_streamRec = 0x0, m_refCount = 0x790cd0, m_pages = std::map with 7947120 elements<error reading variable: Cannot access memory at address 0x18>,
  m_pixelBuffer = std::vector of length 0, capacity 0}

I've tried to make minimal code:
#include <SFML/Graphics.hpp>
#include <iostream>

int main(int argc, char* argv[])
{
        sf::Font font;
        if (!font.loadFromFile("Resources/Fonts/Terminus.ttf"))
                std::cerr << "Font not loaded";
        return 0;
}
and look at font after initialization... and it was initialized ok!
font = {m_library = 0x604db0, m_face = 0x6030f0, m_streamRec = 0x0, m_refCount = 0x604a40, m_pages = std::map with 0 elements, m_pixelBuffer = std::vector of length 0, capacity 0}

Also about weirdness: i didn't alternate font loading and related code for a long while. It just suddenly stopped working.

2
Graphics / [SOLVED] Text blurred on some positions
« on: April 11, 2014, 03:41:07 pm »
Please see attached image, it is self-descriptive. Why text in middle of screen is blurred while text on the edges is ok? Is it #228 issue? I still got sfml2.1

3
Graphics / [SOLVED] setPosition of composite transformable class
« on: March 28, 2014, 02:14:02 pm »
I'm trying to make TextField widget, here's header:
class TextField: public sf::Drawable, public sf::Transformable
{
        public:
                TextField(sf::Font& font, unsigned int charSize, const std::string& content, const sf::Vector2f& size);
                void setFocused(bool state);
                std::string getText() const;
                void setBackgroundColor(sf::Color);
                void processInput(sf::Event event);
                void draw(sf::RenderTarget& target, sf::RenderStates states) const;
                void clear();
                sf::Vector2f getSize() const;
        private:
                sf::RectangleShape background;
                sf::Text text;
                std::string string;

                sf::Color focusedColor;
                sf::Color unfocusedColor;
                };
 
As you can see it's just wrapper with rectangle inside and text on top of it and bunch of helper functions.

I've figured out how to draw passing it to the window, by inheriting from drawable and overloading draw method.

But i can't figure out how to make setPosition method for this class. Documentation suggests just inheriting from Transformable and using inherited setPosition method and all will be fine.
However it's doesn't work - position remains 0,0 whatever is passed to setPosition.

Transformable::setPosition isn't virtual so only option is make my own setPosition, right?
But what's the point in inheriting Transformable then? It doesn't work because i'm doing something wrong?

4
Graphics / [SOLVED] Render to part of window
« on: March 25, 2014, 10:12:33 am »
Hello. I'm making hacker roguelike simulator, kinda like uplink + cataclysm-dda. Majority of time player spends in in-game OS hacking something.
Gui of this os consists of several "windows" like terminal, proxies list, resource consumption monitor and so on.
Contents of each window is drawed by in-game processes which are runned and managed by OS class instance.
Problem is, i don't know how to restrict process drawing to specified rectangle of game window.

Right now i have OperatingSystem::Draw(sf::RenderWindow&) method, which draws background and then calls draw-method of every active process with sf::RenderWindow and sf::Rect which is used by process instance to know where to draw it's contents. I don't like that process could potentially draw anywhere it wants, because whole window is passed in and i must manually take care of this. That's error-prone.

So, what options i know of at the moment:
1) sf::View & viewports looks like something related to my problem. Though in tutorials it looked like it just renders same content, but scaled or resized or something. Didn't investigate it further, though.
2) Maybe make os pass only rect to process's draw method, make process's draw method render to texture with size of passed rect and return this texture to OS and make OS take care of rendering the texture to game window in correct position. Possible drawback: rendering to texture, then rendering to window would decrease perfomance. Or not?

I think second approach is the most elegant one. It also abstracts process of window arrangement in OS.
What would you advise?

p.s. english isn't my native language, sorry about mistakes and if you didn't understand something please tell - i'll try to explain better


 

Pages: [1]