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

Author Topic: Crash when resetting view  (Read 1631 times)

0 Members and 1 Guest are viewing this topic.

TheGuerilla

  • Newbie
  • *
  • Posts: 27
  • Cynical Prick.exe
    • View Profile
    • Email
Crash when resetting view
« on: May 07, 2016, 08:39:07 am »
This is probably a stupid question, but humor me anyway. When I call sf::View::reset I get this nice little throw

When I looked this up, I found one of the admins say that SFML doesn't throw exceptions, so I don't know what the deal is there. This is the actual code I use where its called:
void SER::View::setup(float x, float y, float width, float height, float rot, float scale, float portX, float portY, float portW, float portH) {
        view.reset({ x, y, width, height });

        this->x = x;
        this->y = y;
        this->width = width;
        this->height = height;
        viewX = portX;
        viewY = portY;
        viewW = portW;
        viewH = portH;
        this->rot = rot;
        this->scale = scale;

        view.setRotation(rot);
        view.zoom(scale);

        if (portW == -1) {
                viewW = view.getViewport().width;
                viewH = view.getViewport().height;
        }
}
As you can see, that is a function, that has a definition in a header file like this:
void setup(float x, float y, float width, float height, float rot = 0, float scale = 1, float portX = 0, float portY = 0, float portW = -1, float portH = -1);
(I'm assuming that part is important because it has default arguments.)

When I call it, I set the x/y/width/height to -32,0,320,240 (The size of the window starting at -32.), and I get that nice little crash right away. The crash happens at the reset call, I know because I used printf to test it and the VS debugger is backing that with the break arrow, so no question there.

So I guess is what did I do wrong? Sorry if this is a stupid question, I just find the sf::View class to be really confusing.

fallahn

  • Sr. Member
  • ****
  • Posts: 492
  • Buns.
    • View Profile
    • Trederia
Re: Crash when resetting view
« Reply #1 on: May 07, 2016, 09:10:03 am »
Access violation writing location 0x0000

suggests you're trying to access a nullptr (ie a pointer with value zero)

TheGuerilla

  • Newbie
  • *
  • Posts: 27
  • Cynical Prick.exe
    • View Profile
    • Email
Re: Crash when resetting view
« Reply #2 on: May 07, 2016, 07:35:01 pm »
You were right, the pointer calling this function hadn't been initialized. Thanks a ton!

 

anything