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

Author Topic: Crashing with drawTo Function.  (Read 926 times)

0 Members and 1 Guest are viewing this topic.

Christopher Jozwiak

  • Newbie
  • *
  • Posts: 48
    • View Profile
    • Blog
    • Email
Crashing with drawTo Function.
« on: January 22, 2017, 04:55:24 pm »
Hello,
I've been trying to figure this out on my own.  I just started playing around with SFML again and I usually am able to move stuff around to make it work but I want to be able to understand what actually is going on.  I've had problems simplifying my code in the past to where the issue is, but here goes nothing.

Grid Class
Grid::Grid(int arraySize){
    arraySize = arraySize;
    gridLines[arraySize];
    std::cout << arraySize;
}
void Grid::drawTo(sf::RenderWindow &mWindow)
{
    for (int tRun = 0; tRun <= arraySize; tRun++){
    mWindow.draw(gridLines[arraySize]);

    }
Main Class
//Everything else in the file is irrelevant (Game Loop Stuff)
grid.drawTo(gameWindow);
 
Noob C++ Programmer.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Crashing with drawTo Function.
« Reply #1 on: January 22, 2017, 07:54:59 pm »
You should use tRun when accessing the array and not it's size which will point to an invalid position (valid elements are from 0 to size-1).
Even better I suggest to use std :vector and a range based for loop. So you won't have to pass around any sizes and won't have to deal with array indices.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything