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

Author Topic: Seems like draw function is crashing my program  (Read 1380 times)

0 Members and 1 Guest are viewing this topic.

savked

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Seems like draw function is crashing my program
« on: November 03, 2017, 04:37:11 pm »
void DrawingNumbers::Animation(sf::RenderWindow &m_window)
{
    m_possibleNum.resize(48);

    int j = 1;
    for(int i = 0; i < 48; i++)
    {
        m_possibleNum[i] = j;
        j++;
    }

    std::random_shuffle(m_possibleNum.begin(), m_possibleNum.end());

    // loading texture to sprite
    for(int i = 0; i < 35; i++)
    {
        m_drawnNumber[i].setTexture(m_tx[m_possibleNum[i]]);
        m_drawnNumber[i].setScale(sf::Vector2f(0.120f, 0.120f));
    }

    // drawing
    for(int i = 0; i < 35; i++)
    {
        m_window.draw(m_drawnNumber[i]);
    }

}

m_drawnNumber is an array
m_possibleNum is a vector

I call this function in main and my program runs (white screen) and breaks with "Process returned -1073741819 (0xC0000005)".
I ran a debugger and these errors popped up https://imgur.com/a/oxYWs

(Izvlacenje::Animacija = DrawingNumbers::Animation) I translated it to English, so you can understand.
« Last Edit: November 03, 2017, 04:40:30 pm by savked »

achpile

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • Achpile's homepage
    • Email
Re: Seems like draw function is crashing my program
« Reply #1 on: November 03, 2017, 07:53:20 pm »
Are you sure m_drawnNumber contains 35 valid elements? paste it's initialization

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Seems like draw function is crashing my program
« Reply #2 on: November 04, 2017, 09:06:04 am »
Why are you using those magic numbers, and not the actual size() of these vectors?
Laurent Gomila - SFML developer