Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


SFML Error! :(


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
15 replies to this topic

#1 superman3275   Crossbones+   -  Reputation: 2061

Like
0Likes
Like

Posted 14 October 2012 - 02:23 PM

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 ph34r.png!

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 smile.png!


Sponsor:

#2 JTippetts   Moderators   -  Reputation: 8598

Like
0Likes
Like

Posted 14 October 2012 - 04:23 PM

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.

#3 superman3275   Crossbones+   -  Reputation: 2061

Like
0Likes
Like

Posted 14 October 2012 - 04:41 PM

How can I use visual studios debugger?

I'm a game programmer and computer science ninja ph34r.png!

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 smile.png!


#4 superman3275   Crossbones+   -  Reputation: 2061

Like
0Likes
Like

Posted 14 October 2012 - 04:42 PM

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 ph34r.png!

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 smile.png!


#5 SiCrane   Moderators   -  Reputation: 9629

Like
0Likes
Like

Posted 14 October 2012 - 04:44 PM

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.

#6 superman3275   Crossbones+   -  Reputation: 2061

Like
0Likes
Like

Posted 14 October 2012 - 04:46 PM

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 ph34r.png!

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 smile.png!


#7 SiCrane   Moderators   -  Reputation: 9629

Like
0Likes
Like

Posted 14 October 2012 - 04:48 PM

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.

#8 Serapth   Crossbones+   -  Reputation: 5594

Like
0Likes
Like

Posted 14 October 2012 - 05:23 PM

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.

#9 superman3275   Crossbones+   -  Reputation: 2061

Like
0Likes
Like

Posted 14 October 2012 - 05:43 PM

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 ph34r.png!

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 smile.png!


#10 SiCrane   Moderators   -  Reputation: 9629

Like
1Likes
Like

Posted 14 October 2012 - 06:24 PM

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.

#11 superman3275   Crossbones+   -  Reputation: 2061

Like
0Likes
Like

Posted 14 October 2012 - 06:39 PM

Yes SiCrane, that's exactly the numbers! It says it is uninitialized by (3435973836 x 3435973836) two times, for two images. Can you elaborate on the member variable constructor order problem that you described :)?

I'm a game programmer and computer science ninja ph34r.png!

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 smile.png!


#12 SiCrane   Moderators   -  Reputation: 9629

Like
0Likes
Like

Posted 14 October 2012 - 07:37 PM

When an object is constructed, first any base classes are constructed, then its member variables are constructed in order of declaration in the class definition, regardless of what order you put them in the member initialization list. If you use one member variable to initialize another member variable in the member initialization list of a constructor you need to be sure that any member variable referenced actually appears above in the class definition. The easiest way to do this is to make sure that your member initialization list always follows the same order as the class definition and don't reference member variables that appear later. MSVC is unfortunately just about the only major compiler on the planet that won't give you a warning for not putting your member initialization list in class declaration order (which is frankly stupid).

#13 superman3275   Crossbones+   -  Reputation: 2061

Like
0Likes
Like

Posted 14 October 2012 - 07:45 PM

I did that, and now It shows the ball moving, you can't move your paddle, and none of the blocks are displayed. Well, I'm still trying to fix it :(.

I'm a game programmer and computer science ninja ph34r.png!

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 smile.png!


#14 superman3275   Crossbones+   -  Reputation: 2061

Like
0Likes
Like

Posted 14 October 2012 - 08:08 PM

Okay, I'm not trying to fix it. I need to do something simpler. I do not have the knowledge required yet to make breakout. I am now going to attempt a space invaders clone, or maybe something of the sort. This project is dead, and the code design is stupid. I need to start preplanning, creating interfaces, and designing my classes better.

I'm a game programmer and computer science ninja ph34r.png!

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 smile.png!


#15 Serapth   Crossbones+   -  Reputation: 5594

Like
4Likes
Like

Posted 14 October 2012 - 08:39 PM

I need to start preplanning, creating interfaces, and designing my classes better.


To be honest, you don't. You aren't really at that stage yet where you should really be worrying about design all that much.

What you should focus on is figuring out *WHY* your current project doesn't work. You can't design around a problem you don't understand.

It's a frustrating experience, working through a problem you don't understand, but it is a valuable part of learning anything. Switching from Breakout to Space Invaders will not help you in the least. Now, if your problems are stemming from an overly complicated design ( aka, biting off more than you can chew ), by all means, revisit and simplify, but don't abandon a project just because you can't get it to work. The most likely reason is a lack of understanding of the language itself, which is a problem you are going to have to face and starting over isn't how you do it.

Finally, and I will say this like a broken record... you can't skip the learning curve, don't bother trying. You really are just going to make things harder on yourself over all.

I don't mean to be harsh, but comments like this are extremely telling:

How can I use visual studios debugger?

Instead of starting a new project, this is EXACTLY what you should be learning next. You will advance your skillset a thousand fold more by learning how to debug, than you will by going from one game type to another. Until you have a pretty solid grasp of debugging, you will never really understand code. Trust me on this, the insight you will gain from interacting with your code as it runs will be a massive eye opener.

A quick google turned up this introduction (pdf link) which seems pretty good. It also turned up a lot of crap tutorials too, oddly debugging seems to be something people did a lousy job of explaining... the one intro do debugging tutorial ( one of the top results ), jumped straight in to disassembly, perhaps the last thing a beginner needs to know.... There also appear to be a ton of video tutorials on YouTube, but I've personally never been a fan of a) video tutorials b) YouTube.

Edited by Serapth, 14 October 2012 - 08:50 PM.


#16 SiCrane   Moderators   -  Reputation: 9629

Like
0Likes
Like

Posted 15 October 2012 - 07:32 PM

Judging by your errors, the problem isn't that breakout is too complicated for you, the problem is that you're trying to tackle too much of the complexity all at once. Start in smaller chunks and grow slowly, testing as a you go. Don't try constructing a ball, paddle and bricks all at once. First put in the paddle, then maybe see about moving it around and then put in something else.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS