Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Making my own Render Queue with Drawables  (Read 1837 times)

0 Members and 1 Guest are viewing this topic.

HaedHutner

  • Newbie
  • *
  • Posts: 3
    • View Profile
Making my own Render Queue with Drawables
« on: April 08, 2017, 12:46:47 pm »
Right, so I'm very new to sfml and computer graphics in general. I tired my hand at OpenGL a while ago and that experience sort of put me off OpenGL for a while, which is why I've been playing around with SFML recently.

What I'm trying to do is to create my own render queue, which can then render all of it's drawables to any RenderTarget:

#include "RenderQ.h"

namespace game {
        namespace renderer {

                RenderQ::RenderQ()
                {
                        _queue = std::vector<sf::Drawable *>();
                }

                void RenderQ::submit(sf::Drawable * drawable)
                {
                        _queue.push_back(drawable);
                }

                void RenderQ::clear()
                {
                        _queue.clear();
                }

                void RenderQ::drawAll(sf::RenderTarget& target)
                {
                        for (int i = 0; i < _queue.size(); i++) {
                                target.draw( *_queue[i] );
                        }
                }

        }
}
 

I can submit to the queue just fine. The problem comes when I call drawAll.

I'm not entirely certain what happens or why it breaks, but it throws this error at me and I've unsuccessfully spent a couple of hour trying to figure out where it comes from:

Exception thrown at 0x000007FEE184894B (sfml-graphics-2.dll) in SFML.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

I'm not entirely certain what sort of information I can get from the error. It's not very descriptive, and I'm not entirely certain on how to do proper error handling ( or in fact, catching ) with SFML. Any sort of help would be greatly appreciated.

Thanks in advance!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Making my own Render Queue with Drawables
« Reply #1 on: April 08, 2017, 01:30:02 pm »
Given the error message, you seem to try and access a null pointer. Make sure that all your pointers are valid.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

HaedHutner

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Making my own Render Queue with Drawables
« Reply #2 on: April 08, 2017, 01:52:35 pm »
Given the error message, you seem to try and access a null pointer. Make sure that all your pointers are valid.

Indeed. Immediately upon realizing this, I went and declared the shape I wanted drawn on the heap instead and it worked. What can I say, pointers still confuse me some times. Oops.

Anyway, thanks for the reply! :D

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Making my own Render Queue with Drawables
« Reply #3 on: April 08, 2017, 02:02:14 pm »
You don't necessarily need to allocate it on the heap, but you need to make sure the object the pointer points to stays alive. Keep in mind that your render queue should not handle the lifetime of your objects.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

HaedHutner

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Making my own Render Queue with Drawables
« Reply #4 on: April 08, 2017, 02:16:56 pm »
You don't necessarily need to allocate it on the heap, but you need to make sure the object the pointer points to stays alive. Keep in mind that your render queue should not handle the lifetime of your objects.

What would you say is a better way to keep the objects alive then?