SFML Error! :(

Started by
14 comments, last by SiCrane 11 years, 6 months ago
So, I'm getting this error:


10.0/vc/include/vector
Line: 932
Expression: Vector Subscript out of range


Whenever I create a MainGame object(The code is below) I get this error.
I'm pretty sure I'm using constructors wrong or I'm doing something with vectors that's stupid, but I can't track down the error(Believe me I'm trying!).

Download Code Here

I'm a game programmer and computer science ninja !

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here !

Advertisement
Your code's a little messy and confusing:

1) Your main.cpp doesn't seem to be your actual main.cpp, since it's just basically a HelloWorld

2) Your actual main.cpp seems to be BREAKOUT.cpp. And in that file, you instance an object of type GameMain and call it MainGame. Crikey, confusing much?

3) Your post indicates you are creating a MainGame object, but you are actually creating a GameMain object. (Unless BREAKOUT.cpp is not your actual main.cpp)

This kind of thing makes it hard to convince anyone to take a look at your code.

That being said, have you tried stepping through with the debugger? Knowing exactly which line triggers the exception, and what the current state values are, can go great lengths toward knowing what the problem is.
How can I use visual studios debugger?

I'm a game programmer and computer science ninja !

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here !

Oh, and BREAKOUT.cpp is Main.cpp, in visual studio your "actual" main.cpp has your solutions name, Sorry for the misunderstanding :).
I should rename that! I'm not sure what I should name it too, I'll think about it.
Typo! Sorry!

I'm a game programmer and computer science ninja !

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here !

1) Again, if you're sharing you code, don't include things like the contents of the Debug/ directory in the archive.
2) It looks like the problem is in your GameDraw constructor, which tries to assign to elements of a vector that you didn't initialize.
3) Also, even if that did work, it would probably break later because you're passing a vector to that function by value, which makes a temporary copy, and then tries storing pointers to the elements of that temporary vector. When the constructor finishes running the temporary vector gets destroyed and you're left with pointers to destroyed objects.
1) I forgot! Stupid me. I'll do that next time.
2) I figured as much, I'll try passing by reference.
3) Same as answer two, I'll pass by reference.

Thanks for the help, I'll update you if I fix it.

I'm a game programmer and computer science ninja !

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here !

Passing by reference won't fix number two, the vector you are assigning to doesn't have any elements in it. You either need to initialize it in the member initializer list, resize() it before you start accessing it, push_back() the pointers you are storing, or something else that actually allocates members in the vector.

1) Again, if you're sharing you code, don't include things like the contents of the Debug/ directory in the archive.


To this point, I had to share a number of C++ projects in the past so I created a utility that cleaned them up shrinking them down. You may find it useful.
So I fixed it doing everything you did, But now it says my image file is too large!
it says it's this (in format: amount of pixels width x amount of pixels height ): (300000000 pixels by 300000000 pixels) and it won't load the images! What?

I'm a game programmer and computer science ninja !

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here !

Does it actually say 3435973836 or 3452816845? Those would be the decimal values for 0xCCCCCCCC or 0xCDCDCDCD which are MSVC fill patterns for uninitialized memory. One is for uninitialized heap and the other for uninitialized stack. At a guess, you've run into the member variable constructor order problem, which happens when the compiler constructs member variables in order of their declaration in the class definition and not the order you specify in the member initialization list.

This topic is closed to new replies.

Advertisement