Page 1 of 2 12 LastLast
Results 1 to 10 of 17
  1. #1
    Join Date
    May 2011
    Posts
    95

    Probably need an expert debugger on this one... grrrrr.

    AAAARGGGGHHHARAHHHH. ok.. now that that is out of my system.. I cannot get this to run at ALLLL! At first the error i got from visual studio was "missing ';' before '*' which.. why is that even an error code? in what situation would you declare a pointer as " char;*level" ... so suspecting my compiler is dumb and it must've been something wrong with my header files i changed a bunch of places where I included things, and now it's even more broken. So ive posted my code up here and if you want me to email you the files so you can open them up in visual studio just message me.PLEASE HELP!!!!

    and trust me.. i HATE hate hate hate not being able to figure something out on my own.. ive been debugging this for 2 days straight going over all my hierarchies, syntaxes etc.. i'm.. tapping out.. so heres the code

    http://pastebin.com/YgjWC6Uk

    also.. ive only been programming for about a semester so.. keep that in mind before yelling at me about my formatting.
    Last edited by frostbytes89; 07-22-2013 at 06:28 PM.

  2. #2
    Join Date
    Jul 2006
    Location
    San Diego, CA, USA
    Posts
    897
    If you want to send me your complete project it would be easier (and faster) for me to debug your app. You can zip up and send to me your project via email.

  3. #3
    Join Date
    Mar 2006
    Location
    South Australia
    Posts
    4,521
    With C++, you should generally only look at the first error the compiler gives you. After a C++ compiler finds an error, it basically messes everything up from then on.

    In this case, you have:

    C2504: 'Sprite' : base class undefined character.h line 8
    C2061: syntax error: identifier 'DrawEngine' character.h line 10
    C2143: syntax error: missing ';' before* game.h line 40

    The first error is the important one. For whatever reason, the compiler could not find the class named Sprite. Are you sure you've named the file in the same way as you are including (Sprite.h vs sprite.h)? Have you forgotten a ; at the end of a class definition somewhere?

    The other two errors are all follow-ons from the first one. The second error is simply the compiler not having any idea what DrawEngine is. This is because DrawEngine is included by Sprite, which the compiler has already told you it has problems with. The third error is that the compiler didn't know what Character was, because of the first error in character.h. Ignore all the errors, fix the first one, recompile, and see what that leaves you.

    Now, having said that, you have waaaay more #includes than you need to, which could be causing you problems. For example, Game.h includes DrawEngine.h, which in turn includes Game.h again. These circular dependencies can cause lots of problems when compiling code. My suggestion would be to remove all of your #includes. Recompile, and look at the errors. Then start adding includes that you need back in one at a time, recompiling after each one. You'll end up with far fewer includes (DrawEngine.h has no need for Game.h, because it doesn't use it anywhere).

    It will take a little while, but I think it will fix your problems.

  4. #4
    Join Date
    May 2011
    Posts
    95
    Okay, thanks a lot for the suggestions. I went through all of my includes and made forward class declarations where possible and now it compiles! So i was very excited!! However... It does not draw sprites properly.. or at all.. and.. I feel discouraged actually almost like.. if I can't figure out why it isn't drawing then I shouldn't even be pursuing this level of code.
    I would need somebody to either A. teach it to me or B give me source code so that i can figure out what is going on. Since those videos do neither I'm not sure what to do.. Joel talks so fast and codes so fast he can't even keep from making his own mistakes let alone slow down enough to explain why he's doing what he's doing. The entire video is practically a copy and paste job. Of course, this is from the eye of a beginner and granted that video is probably not aimed towards a beginner. You two have been very helpful though. If anybody wants to figure out why my sprites aren't printing I would be extremely greatful. Here is my new code that fully compiles. I've been trouble shooting for hours now and trying to debug to figure out what is going on behind the scenes and.. I just can't figure it out.

    http://pastebin.com/St2Ub7L0

    i seriously feel like a complete noob right now. ive never had this hard of a time with any program.

  5. #5
    Join Date
    Jul 2006
    Location
    San Diego, CA, USA
    Posts
    897
    I was on my way out the door when I saw this request but it looks like you got some good help. I agree with what Mr. C. said and would add this. Lean toward putting #includes in the. cpp files rather than in the headers. The avoids circular dep. as he said. You only need the #include when the full definition of the object is needed. Often times just a forward declare will suffice.

  6. #6
    Join Date
    May 2011
    Posts
    95
    Quote Originally Posted by smjones View Post
    I was on my way out the door when I saw this request but it looks like you got some good help. I agree with what Mr. C. said and would add this. Lean toward putting #includes in the. cpp files rather than in the headers. The avoids circular dep. as he said. You only need the #include when the full definition of the object is needed. Often times just a forward declare will suffice.
    right, yeah i got it to compile but i cant get it to draw srpites now >:|. can i still email it to you?

  7. #7
    Join Date
    Mar 2006
    Location
    South Australia
    Posts
    4,521
    Unfortunately I can't test the code - I can only build on Linux or Mac. However, don't get too discouraged. Debugging graphical programs can be quite frustrating, because a lot of the time if things don't quite work, you'll just get a black screen. Often it is a single line of code that needs changing.

    Try printing lots of information to the console to make sure the code is working as you expect. Also try stepping through the code in the debugger to see if the code is being called how you expect.

  8. #8
    Join Date
    Jul 2006
    Location
    San Diego, CA, USA
    Posts
    897
    Yes feel free to send the project. I sent you a message with my email.

    EDIT: Continuing a bit on what I was saying before. In your header when you use native types like int and float the compiler knows exactly what these are. Actually it cares more about how big in bytes they are so it can allocate memory for them. When you declare an object of a custom type (eg. class, struct) in the header then you must include the definition for that type. The definition is the class declaration and we typically put this in a header although its not limited to a .h type file. Again like native types this lets the compiler know exactly how big your type is in bytes. Its better to put the #include in the cpp file because we typically do not #include cpp files all over the place. But only #include what you are actually using in that file or you will just bloat your code with code that doesn't get used. A #include will literally copy the file, the whole thing character by character, right where it is stated.

    This example requires the full definition for MyPoint so you include it. Typically we declare classes in header files so you #include that header file. The object "position" is of type MyPoint which is a custom class and the compiler does not know by default what it looks like or how big it is. So we need to tell it.
    Code:
    #include "MyPoint.h"
    
    class MySpriteClass
    {
    public:
    
      MyPoint position;
    };

    This sample only needs a forward declaration for MyPoint because the compiler knows how big a pointer type is. Since you are declaring a pointer to a MyPoint it knows that variable is 4 bytes on a 32-bit OS. So it knows how to allocate memory for MySpriteClass. It only needs to be told that MyPoint is a class but it does not need the full definition (ie. how big in bytes it is). The same thing applies if you had a reference to an object rather than a pointer to one. You only need a forward declare.
    Code:
    class MyPoint;  // forward declaration
    
    class MySpriteClass
    {
    public:
    
      MyPoint*  pPosition; // declaring a pointer variable which has a known size to the compiler
    };
    Last edited by smjones; 05-24-2011 at 10:38 AM.

  9. #9
    Join Date
    Jun 2003
    Location
    Trier, Germany
    Posts
    1,350
    first of all:
    Code:
    typedef struct _Vector
    {
    	float x;
    	float y;
    } _Vector;
    2 things here: you don't need the typedef in C++. and you must not name anything with a leading underscore followed by a capital letter or another underscore (these names are reserved for the compiler by the standard). none of this will trigger any errors here, it's just a matter of style:

    Code:
    struct Vector
    {
    	float x;
    	float y;
    };
    now for your problem:
    Code:
    Character::Character(DrawEngine *de, int s_index, float x, float y,
    			  int lives, char upKey1, char downKey1, char leftKey1,
    			  char rightKey1) : Sprite(de, s_index, x, y, lives)
    {
    	upKey = upKey;
    	downKey = downKey;
    	leftKey = leftKey;
    	rightKey = rightKey;
    
    	classID = CHARACTER_CLASSID;
    }
    this is a typical beginner error, so don't feel bad for it: you are overloading names here. what you meant was
    Code:
    this->upKey = upKey
    but you wrote means something different: it assigns the variable upKey that was passed in as a parameter to *itself*. so in fact you do nothing
    this comes from the fact how names are handled in c++ (and most other programming languages): if you use the same name twice, all use of that name will always refer to the innermost variable. consider the following code if you have trouble imagining this:
    Code:
    int i = 23;
    std::cout << i << "\n";
    do {
        int i = 42;   //another i
        std::cout << i << "\n";   //refers to the innermost i
    } while(false);
    std::cout << i << "\n";   //and the outer i again
    this error causes the upKey/downKey/... of your Character class do remain uninitialized which messes up your whole event handling. it is always a good idea to chose separate names for class members and parameters. we actually had a lengthy discussion on this not too long ago... (edit: i think it was this thread)
    judging from a hasty readthrough, that should fix your problem... if not, feel free to return
    Last edited by ComicSansMS; 05-24-2011 at 01:46 PM.

  10. #10
    Join Date
    Oct 2009
    Posts
    28
    Print lots of stuff to the console
    Good advice. I'm in the button making part of the openGL tutorials, and my buttons are having issues. I just discovered that my buttons "inside" variable is always true, by using the write to console method. I've been coding for over TWO YEARS, good sir, and I'm having similar problems to you- compiled code that doesn't work properly at runtime. Its a programming norm, and its our job to find out why.

    You are not a noob, C++ is just crazy. Don't be discouraged, you will pick it up more and more as you go. This is coming from someone who has endured similar things! =)

    Edit:

    Just to add on to that and make you feel more powerful, I got my buttons "inside' variable to work correctly, but... My text draws out of place. Its not even touching the button.

    These issues are a normal part of coding, so once again, don't be discouraged!
    Last edited by Scyth3s; 05-25-2011 at 10:55 AM.

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •