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

Author Topic: Crashing with drawTo Function.  (Read 901 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 »
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;
    std::cout << arraySize;
void Grid::drawTo(sf::RenderWindow &mWindow)
    for (int tRun = 0; tRun <= arraySize; tRun++){

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


  • SFML Team
  • Hero Member
  • *****
  • Posts: 10777
    • 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/