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

Author Topic: Program not starting  (Read 1911 times)

0 Members and 1 Guest are viewing this topic.

Jalfor

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Program not starting
« on: July 13, 2011, 06:04:39 am »
Well, I have cut down the code as much as I possibly can and I have spent...a long time trying to work out what the problem is. I'm not quite sure if this is a C++ problem or an SFML problem. Anyway, here is the cut down version that doesn't work. It's saying it has an access violation at <massive bunch of number>. Tell me if you need the massive bunch of numbers or the exact output of the error thing.

Code: [Select]
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

int main()
{
int gridx = 10;
int gridy = 10;
int x1 = 120;
int y1 = 100;
int x2 = 100;
int y2 = 80;
sf::Shape grid[10][10]; //The grid on which everything is drawn
    sf::RenderWindow App(sf::VideoMode(800, 600), "Snake");
 
while (App.IsOpened())
{
int xdot = gridx;
int ydot = gridy;

//Draw it
for (xdot = gridx; xdot > 0; xdot--)
for (ydot = gridy; ydot > 0; ydot--)
{
grid[xdot][ydot] = sf::Shape::Rectangle(x1 + xdot * 22, y1 + ydot * 22, x2 + xdot * 22, y2 + ydot * 22, sf::Color::Red);
App.Draw(grid[xdot][ydot]);
}
App.Display();
}
return EXIT_SUCCESS;
}
If a picture tells 1000 words, then a YouTube video clearly tells 1000000 making a YouTube video obviously a larger work than the Lord Of The Rings, or some other massive novel. Thus are the laws of YouTube videos.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Program not starting
« Reply #1 on: July 13, 2011, 07:49:53 am »
Your grid array has elements from 0 to 9, but you access indices from 10 to 1 in your loop.

Your loop should look like this instead:
Code: [Select]
for (xdot = gridx - 1; xdot >= 0; xdot--)
(is the backward iteration really needed here??)
Laurent Gomila - SFML developer

Jalfor

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Program not starting
« Reply #2 on: July 13, 2011, 10:59:10 am »
Oh...that was stupid, I thought that was the problem and I must have tried fixing it up the wrong way. Anyway, thanks for the help  :)

As for backwards iteration, no, it's not though it doesn't make a difference does it?
If a picture tells 1000 words, then a YouTube video clearly tells 1000000 making a YouTube video obviously a larger work than the Lord Of The Rings, or some other massive novel. Thus are the laws of YouTube videos.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Program not starting
« Reply #3 on: July 13, 2011, 11:02:46 am »
Quote from: "Jalfor"
As for backwards iteration, no, it's not though it doesn't make a difference does it?
No, but if there are multiple equivalent ways of doing something, people usually choose the straightforward way ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: