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 - Mörkö

Pages: [1]
1
Graphics / segfault when copying pixels
« on: June 28, 2019, 08:32:38 pm »
In the following code, the resulting texture is garbled when drawn:

    sf::Image img = texture.copyToImage();
    const sf::Vector2u img_size = texture.getSize();
    const sf::Uint8 * pixels = img.getPixelsPtr();
    const std::size_t array_size = img_size.x * img_size.y;
    sf::Uint8 * _pixels = new sf::Uint8[array_size];
    for (std::size_t i = 0; i < array_size; i++) {
        _pixels[i] = pixels[i];
    }
    texture.update(_pixels, 256, 256, 0, 0);

but using the orignal pixels array is no problem. Valgrind reports the following:

==16020== Invalid read of size 8
==16020==    at 0x4C3416E: memcpy@GLIBC_2.2.5 (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==16020==    by 0xB98CDA2: ??? (in /usr/lib/x86_64-linux-gnu/dri/r600_dri.so)
==16020==    by 0xB991D90: ??? (in /usr/lib/x86_64-linux-gnu/dri/r600_dri.so)
==16020==    by 0xB6E91D4: ??? (in /usr/lib/x86_64-linux-gnu/dri/r600_dri.so)
==16020==    by 0xB6673B4: ??? (in /usr/lib/x86_64-linux-gnu/dri/r600_dri.so)
==16020==    by 0xB669F5F: ??? (in /usr/lib/x86_64-linux-gnu/dri/r600_dri.so)
==16020==    by 0xB66D3C7: ??? (in /usr/lib/x86_64-linux-gnu/dri/r600_dri.so)
==16020==    by 0x5294FCF: sf::Texture::update(unsigned char const*, unsigned int, unsigned int, unsigned int, unsigned int) (in /usr/lib/x86_64-linux-gnu/libsfml-graphics.so.2.4.2)

What am I doing wrong?

2
General / Initial draw call slow
« on: March 09, 2016, 01:12:06 am »
Why does the first call to draw with some vertices cause a huge lag?

Example:
int main() {
    sf::RenderWindow window{sf::VideoMode{640, 480}, "SFML"};
    for (auto n : {1, 2, 3}) {
        Timer p{"Draw"};
        if (n > 1)  window.draw(sf::RectangleShape{});
        else        window.draw(sf::VertexArray{sf::Triangles});
    }
}

Typical output:
Draw 0.031ms
Draw 167.891ms
Draw 0.006ms

3
Graphics / View move when zoomed
« on: March 06, 2016, 07:33:45 am »
How can I make a view move the same amount regardless of zoom? For example, if I zoom out and move, the view then moves by the same amount it would by default, but I want to make it move by the greater amount relative to the zoom instead.

I hope the question is clear, otherwise I can elaborate if needed.

4
Graphics / Stretching image to fit window size
« on: February 13, 2015, 10:48:08 am »
I want to draw everything according to a fixed frame, say 1600x900, and then stretch or shrink the complete image according to actual window size. For example if the window is 1920x1080 then everything is slightly stretched but if it's 1024×768 then the image is shrunk down.

The SFML window seems to do this automatically if I create a window, draw something and manually resize the window, but how do I achieve the same effect by default?

5
Graphics / sf::Texture load from memory
« on: January 14, 2015, 05:34:57 pm »
Hi. I'm having trouble figuring out how sf::Texture::loadFromMemory works. I would be grateful if you could demonstrate a complete minimal working example how to use it.

If you don't want to generate your own image, then you may take one of these:

(click to show/hide)

(click to show/hide)

Thanks.

6
SFML website / Youtube embedded videos not working
« on: July 28, 2014, 01:09:12 pm »
For me it seems like videos in posts doesn't work. It just shows the gray box with a message about needing to install a plugin.

To make things clear: I do not have flash installed.

I do not know anything about web coding, but my guess is the forum doesn't support the HTML5 player perhaps. I can watch videos on youtube and other sites with embedded videos just fine, so I'm hoping it's not too big of a deal to fix this problem.

Using Mozilla Firefox and gnome version of Fedora 20 GNU+linux.

7
Window / Generate Event::Closed programatically?
« on: July 10, 2014, 06:07:08 am »
Hi, so I'm looking for a way to create the sf::Event::Closed event without manually doing anything like pressing the close window button or alt+F4.

From what I can tell, all the ways a user could push custom events are private and hidden, unfortunately!!! Well, unless I mod the SFML source of course, but that's undesirable.

For my testing purposes it would be very convenient to be able to generate events in the code somehow in general, but for the moment I'm specifically looking for a way to make the program emit the Event::Closed event. Is it possible?

8
General / How to enable GLSL 330
« on: June 28, 2014, 11:09:52 am »
Is it true that opengl 3.3 is not supported in SFML 2? I seem unable to set sf::ContextSettings.minorVersion to 3, as that is what I believe would enable me to use glsl version 330.

I was following along in a tutorial, and when I tried to create a shader the program gave some error about NEW_IDENTIFIER, which after googling it seems I was using an outdated version of glsl, so I tried using context settings to get the required version.

X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  153 (GLX)
  Minor opcode of failed request:  34 ()
  Serial number of failed request:  69
  Current serial number in output stream:  68


So I thought maybe I simply have an installed version that is outdated.

[morran@5586577d ~]$ glxinfo
OpenGL vendor string: X.Org
OpenGL renderer string: Gallium 0.4 on AMD CAYMAN
OpenGL core profile version string: 3.3 (Core Profile) Mesa 10.1.5
OpenGL core profile shading language version string: 3.30


My system clearly supports glsl version 330, so why does it seem like SFML doesn't do so too?

What steps can I take to enable opengl 3.3 in SFML?

edit--

Yeah it turns out I didn't understand the meaning of opengl core profile. So I guess my new question is, can I enable that somehow?

edit2--

For example, in SDL I can do this:

SDL_Init(SDL_INIT_VIDEO);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);

SDL_Window* window = SDL_CreateWindow("OpenGL", 100, 100, 800, 600, SDL_WINDOW_OPENGL);
SDL_GLContext context = SDL_GL_CreateContext(window);

char* version = (char*)glGetString(GL_VERSION);
printf("%s\n", version);

And as far as I can tell from my brief testing, it works with no problems.

outputs
3.3 (Core Profile) Mesa 10.1.5

9
General / SFML static compiling for VS13
« on: June 23, 2014, 11:53:32 pm »
So I'm completely new to development in Windows, and aside from a new found gratitude to whoever invented package managers, I've run into some trouble trying to compile against the static libs.

Using Visual Studio Express 2013 and the `Visual C++ 11 (2012) - 32 bits` version of SFML.

I can compile it normally just fine, but when I add SFML_STATIC and change the linker options to sfml-xxx-s-d.lib then I get a bunch of these errors:

Quote
Error   1   error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1800' in Source.obj

and
Quote
Error   29   error LNK2001: unresolved external symbol "__declspec(dllimport) class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::endl(class std::basic_ostream<char,struct std::char_traits<char> > &)" (__imp_?endl@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@1@AAV21@@Z)

What am I doing wrong?

10
General / help decrypting error message
« on: June 12, 2014, 12:00:06 am »
I'm working through the SFML game dev book, and it's pretty great. However, when coding along to the chapter 7 - Warfare Unleashed - Implementing Gameplay I encountered this error, that I haven't been able to figure out on my own:

Quote

22:31:46: Starting: "/usr/bin/make"
g++ -c -pipe -std=c++11 -Wall -Wextra -g -Wall -W -DQT_WEBKIT -I/usr/share/qt4/mkspecs/linux-g++ -I../SFMLbook -I../SFMLbook -I. -o world.o ../SFMLbook/world.cpp
In file included from /usr/include/c++/4.8/set:60:0,
                 from ../SFMLbook/scenenode.hpp:13,
                 from ../SFMLbook/entity.hpp:4,
                 from ../SFMLbook/aircraft.hpp:4,
                 from ../SFMLbook/world.hpp:4,
                 from ../SFMLbook/world.cpp:1:
/usr/include/c++/4.8/bits/stl_tree.h: In instantiation of 'std::_Rb_tree_node<_Val>::_Rb_tree_node(_Args&& ...) [with _Args = {const std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > >&}; _Val = std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > >]':
/usr/include/c++/4.8/ext/new_allocator.h:120:4:   required from 'void __gnu_cxx::new_allocator< <template-parameter-1-1> >::construct(_Up*, _Args&& ...) [with _Up = std::_Rb_tree_node<std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > > >; _Args = {const std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > >&}; _Tp = std::_Rb_tree_node<std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > > >]'
/usr/include/c++/4.8/bits/alloc_traits.h:254:4:   required from 'static typename std::enable_if<std::allocator_traits<_Alloc>::__construct_helper<_Tp, _Args>::value, void>::type std::allocator_traits<_Alloc>::_S_construct(_Alloc&, _Tp*, _Args&& ...) [with _Tp = std::_Rb_tree_node<std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > > >; _Args = {const std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > >&}; _Alloc = std::allocator<std::_Rb_tree_node<std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > > > >; typename std::enable_if<std::allocator_traits<_Alloc>::__construct_helper<_Tp, _Args>::value, void>::type = void]'
/usr/include/c++/4.8/bits/alloc_traits.h:393:57:   required from 'static decltype (_S_construct(__a, __p, (forward<_Args>)(std::allocator_traits::construct::__args)...)) std::allocator_traits<_Alloc>::construct(_Alloc&, _Tp*, _Args&& ...) [with _Tp = std::_Rb_tree_node<std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > > >; _Args = {const std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > >&}; _Alloc = std::allocator<std::_Rb_tree_node<std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > > > >; decltype (_S_construct(__a, __p, (forward<_Args>)(std::allocator_traits::construct::__args)...)) = <type error>]'
/usr/include/c++/4.8/bits/stl_tree.h:408:36:   required from 'std::_Rb_tree_node<_Val>* std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_create_node(_Args&& ...) [with _Args = {const std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > >&}; _Key = Fonts::ID; _Val = std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > >; _KeyOfValue = std::_Select1st<std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > > >; _Compare = std::less<Fonts::ID>; _Alloc = std::allocator<std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > > >; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Link_type = std::_Rb_tree_node<std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > > >*]'
/usr/include/c++/4.8/bits/stl_tree.h:429:55:   required from 'std::_Rb_tree_node<_Val>* std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_clone_node(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Const_Link_type) [with _Key = Fonts::ID; _Val = std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > >; _KeyOfValue = std::_Select1st<std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > > >; _Compare = std::less<Fonts::ID>; _Alloc = std::allocator<std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > > >; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Link_type = std::_Rb_tree_node<std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > > >*; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Const_Link_type = const std::_Rb_tree_node<std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > > >*]'
/usr/include/c++/4.8/bits/stl_tree.h:1087:43:   required from 'std::_Rb_tree_node<_Val>* std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_copy(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Const_Link_type, std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Link_type) [with _Key = Fonts::ID; _Val = std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > >; _KeyOfValue = std::_Select1st<std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > > >; _Compare = std::less<Fonts::ID>; _Alloc = std::allocator<std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > > >; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Link_type = std::_Rb_tree_node<std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > > >*; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Const_Link_type = const std::_Rb_tree_node<std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > > >*]'
/usr/include/c++/4.8/bits/stl_tree.h:659:50:   required from 'std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Rb_tree(const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&) [with _Key = Fonts::ID; _Val = std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > >; _KeyOfValue = std::_Select1st<std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > > >; _Compare = std::less<Fonts::ID>; _Alloc = std::allocator<std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > > >]'
/usr/include/c++/4.8/bits/stl_map.h:181:22:   required from 'std::map<_Key, _Tp, _Compare, _Alloc>::map(const std::map<_Key, _Tp, _Compare, _Alloc>&) [with _Key = Fonts::ID; _Tp = std::unique_ptr<sf::Font, std::default_delete<sf::Font> >; _Compare = std::less<Fonts::ID>; _Alloc = std::allocator<std::pair<const Fonts::ID, std::unique_ptr<sf::Font, std::default_delete<sf::Font> > > >]'
../SFMLbook/resourceholder.hpp:11:7:   required from here
/usr/include/c++/4.8/bits/stl_tree.h:140:49: error: use of deleted function 'constexpr std::pair<_T1, _T2>::pair(const std::pair<_T1, _T2>&) [with _T1 = const Fonts::ID; _T2 = std::unique_ptr<sf::Font, std::default_delete<sf::Font> >]'
    _M_value_field(std::forward<_Args>(__args)...) { }
                                                 ^
In file included from /usr/include/c++/4.8/utility:70:0,
                 from /usr/include/c++/4.8/algorithm:60,
                 from /usr/local/include/SFML/Graphics/Rect.hpp:32,
                 from /usr/local/include/SFML/Graphics/Transform.hpp:32,
                 from /usr/local/include/SFML/Graphics/Transformable.hpp:32,
                 from ../SFMLbook/scenenode.hpp:6,
                 from ../SFMLbook/entity.hpp:4,
                 from ../SFMLbook/aircraft.hpp:4,
                 from ../SFMLbook/world.hpp:4,
                 from ../SFMLbook/world.cpp:1:
/usr/include/c++/4.8/bits/stl_pair.h:127:17: note: 'constexpr std::pair<_T1, _T2>::pair(const std::pair<_T1, _T2>&) [with _T1 = const Fonts::ID; _T2 = std::unique_ptr<sf::Font, std::default_delete<sf::Font> >]' is implicitly deleted because the default definition would be ill-formed:
       constexpr pair(const pair&) = default;
                 ^
/usr/include/c++/4.8/bits/stl_pair.h:127:17: error: use of deleted function 'std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = sf::Font; _Dp = std::default_delete<sf::Font>]'
In file included from /usr/include/c++/4.8/memory:81:0,
                 from ../SFMLbook/scenenode.hpp:11,
                 from ../SFMLbook/entity.hpp:4,
                 from ../SFMLbook/aircraft.hpp:4,
                 from ../SFMLbook/world.hpp:4,
                 from ../SFMLbook/world.cpp:1:
/usr/include/c++/4.8/bits/unique_ptr.h:273:7: error: declared here
       unique_ptr(const unique_ptr&) = delete;
       ^
make: *** [world.o] Error 1
22:31:47: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project SFMLbook (kit: Desktop)
When executing step 'Make'

I've been going over my code and comparing it to the functioning source from the LaurentGomila GitHub page, but I'm just unable to find any difference in my own code.

So from what I can tell this has something to do with std::set, but it's difficult for me to figure out anything else than that, because this traceback message doesn't actually seem to explicitly show where the problem is in my source, but points to a standard library file instead. Following the error through the files ends up at the class declaration of ResourceHolder before going into stl_tree.h.

So please help me figure out what may be causing this error.

--

As an aside, here are some personal remarks not directly related to the issue: I'm using the book as a code along and intro to my first real C++ project. Having learnt programming in python, the transition to C++ was shocking in several ways, mostly due to the extreme complexity of the language and how frequently I must go digging for answers to things which were more or less intuitive in python. I don't have any inherent problem with complexity itself, because this technical kind of problem solving is part of why I enjoy programming so much. However, I do consider C++ a pretty awful language by modern standards, because the nature of it's complexity is that of baggage from decades ago, and implementing too many paradigms to be a good choice for anyone starting out these days.

Well, maybe people feel differently if they are given a formal education starting with C or Java, and can then proceed to view C++ as an improved or more powerful version of what they already knew, but I don't know if that's true.

I will stick with it until I have a solid understanding of `programming in C++` and feel that I'm comfortable using it to start any kind of project. I want to become a programmer and a game dev, so I think having a working knowledge of all the big daddy languages is a must, but I sure do hope I'll be able to code my own games in a more elegant and modern language than this.

11
Graphics / Basic window memory issue
« on: May 28, 2014, 01:00:40 am »
On my system the following code seems to add 10mb or ram per second:

int main() {
    sf::RenderWindow window(sf::VideoMode(320, 240), "");
    sf::Event event;
    while (window.isOpen()) {
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed)
                window.close();
        }
        glClear(GL_COLOR_BUFFER_BIT);
        window.display();
    }
}

In my system monitor, running that shows a steady increase of +10mb memory usage every second. These are my specs:
             .;ldkO0000Okdl;.                user@box
         .;d00xl:,'....';:ok00d;.            OS: openSUSE 13.1 Bottle
       .d00l'                ,o00d.          Kernel: x86_64 Linux 3.11.10-11-desktop
     .d0Kd. :Okxol:;'.          :O0d.        Uptime: 3h 0m
    'OKKKK0kOKKKKKKKKKKOxo:'      lKO'       Packages: 2570
   ,0KKKKKKKKKKKKKKKK0d:,,,:dx:    ;00,      Shell: bash 4.2.45
  .OKKKKKKKKKKKKKKKKk..oOkdl.'0k.   cKO.     Resolution: 1920x1080
  :KKKKKKKKKKKKKKKKK: kKx..od lKd   .OK:     DE: KDE 4.11.5
  dKKKKKKKKKKKOx0KKKd ;0KKKO, kKKc   dKd     WM: KWin
  dKKKKKKKKKKKK;.;oOKx,..'..;kKKK0.  dKd     WM Theme: Oxygen
  :KKKKKKKKKKKK0o;...;cdxxOK0Oxc,.  .0K:     GTK Theme: oxygen-gtk [GTK2]
   kKKKKKKKKKKKKKKK0xl;'......,cdo  lKk      Icon Theme: oxygen
   '0KKKKKKKKKKKKKKKKKKKKK00KKOo;  c00'      Font: Sans Serif
    .kKKKOxddxkOO00000Okxoc;'.   .dKk.       CPU: AMD FX-8120 Eight-Core @ 3.1GHz
      l0Ko.                    .c00l.        GPU: AMD Radeon HD 6900 Series
       .l0Kk:.              .;xK0l.          RAM: 2517MB / 7981MB
          ,lkK0xl:;,,,,;:ldO0kl,            
              .':ldxkkkkxdl:'.  
Using the github version of SFML.

Now, I thought the increase was weird in itself, and not only because I don't quite know how to identify what the actual problem is, but I really thought a lib as established as SFML shouldn't have those kinds of issues (not bashing, just being honest.)

But what's even more weird to me is that the problem seems to be dependent on the resolution of the window, and some other factors. Here are some samples I noted from trying different resolutions:

150x150: 14.9mb memory usage, no noticeable increase.
320x240: Steady memory increase by 10mb every second.
640x480: Same as 320x240.
1600x900: 5mb per second increase.
1920x1080: This is equivalent to `fullscreen windowed mode` for me. Curiously, this shows a 3mb per second increase, but if I grab and move the window so that KDE automatically resizes it to ~1280x680, then the memory stops increasing and stays at whatever it was before I moved it. Manually setting the resolution to that value results in a 7mb per second increase.

If I limit the fps using RenderWindow::setFramerateLimit() then the increase is slowed down in proportion to the rate.

So I guess my questions are: Is this a known problem? Is the problem in my code, rather than a bug in SFML? Problem is in my system? Are there any workarounds to prevent this? Can you explain what is causing the leak? Why do the amounts vary depending on window resolution?

I appreciate any information or advice, thank you.

Pages: [1]