Thread: SDL rectangle pointer error

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    403

    SDL rectangle pointer error

    This code compiles fine but the program crashes.


    //global rectangles
    SDL_Rect *player1, *player2, *credits, *exitt;

    //function to set coords of rectangles
    void SetRects(void)
    {
    cout << "in setrects" << endl;
    player1->x = 1;
    cout << "set player1.x" << endl;
    player1->y = 1;
    player1->w = 94;
    player1->h = 26;
    ...
    }



    when i run this program (yes there is a lot more to it) i see the screen switch modes, and everything that comes before my call to the function SetRects(), but inside setrects the program crashes, i put in the cout statments to find the error and sure enough, i see the words "in setrects" but i never see the "set player1.x" part. What am I doing wrong in this code?

  2. #2
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    The trouble your having is your dereferencing a stray pointer.
    Probably best to do something like

    struct Player {
    int x, y;
    };

    typedef struct Player Player;

    void init_player(Player* p)
    {
    p->x = 1;
    p->y = 1;
    }

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    403

    ahh yes..

    yeah, thanks, can't belive i didn't see that

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 02:39 PM
  3. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM