an odd SDL problem...

This is a discussion on an odd SDL problem... within the Game Programming forums, part of the General Programming Boards category; I am having a really weird problem with SDL right now, maybe someone can shed some light.... I have a ...

  1. #1
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738

    Question an odd SDL problem...

    I am having a really weird problem with SDL right now, maybe someone can shed some light....

    I have a surface which contains a picture of a mouse cursor on it, and I am displaying it to the screen. I have never had any problem displaying surfaces to the screen before, but this one just does not want to display for some reason...

    Here is the code...

    Code:
    int main ( int argc, char * argv[] )
    {
    	...SDL initialization code...
    
    	mouseRect = new SDL_Rect;
    	mousePosRect = new SDL_Rect;
    
    	while ( processMessages(event) )
    	{	
    		drawObjects ( screen );
    	}
    
    	return 0;
    }
    
    bool processMessages ( SDL_Event &event )
    {
    	while( SDL_PollEvent ( &event ) )
    	{
    		switch(event.type)
    		{
    			case SDL_MOUSEBUTTONDOWN:
    				switch(event.button.button)
    				{
    				case SDL_BUTTON_LEFT:
    					break;
    				case SDL_BUTTON_MIDDLE:
    					break;
    				case SDL_BUTTON_RIGHT:						
    					break;
    				}			
    			case SDL_MOUSEMOTION:
                                           mouseX = event.motion.x;
    				mouseY = event.motion.y;
    				break;
    		}
                   }
    	return true;
    }
    
    void drawObjects ( SDL_Surface *screen )
    {		
    	SDL_BlitSurface ( mouseGraphic, mouseRect, screen, mousePosRect ); 
    	
    	SDL_Flip(screen);
    	SDL_FillRect(screen, 0, 0);
    }

    Now....here is the weird thing...it DOES display correctly if I do this:

    Code:
    void drawObjects ( SDL_Surface *screen )
    {		
    	mouseRect = new SDL_Rect();
    	mousePosRect = new SDL_Rect();
    	
    	SDL_BlitSurface ( mouseGraphic, mouseRect, screen, mousePosRect ); 
    	
    	SDL_Flip(screen);
    	SDL_FillRect(screen, 0, 0);
    }
    Of course that is stupid because all the memory allocations would quickly kill the computer, unless I used delete right after the call to SDL_BlitSurface().

    But I dont want to have to do that, because the whole point of mousePosRect is to hold the position of the mouse so it knows where to blit the surface...

    And, if I do this, it suddenly does not work again:

    Code:
    void drawObjects ( SDL_Surface *screen )
    {		
    	mouseRect = new SDL_Rect();
    	mousePosRect = new SDL_Rect;
    
    	mousePosRect->x = mouseX;
    	mousePosRect->y = mouseY;
    
    	SDL_BlitSurface ( mouseGraphic, mouseRect, screen, mousePosRect ); 
    
    	delete mouseRect;
    	delete mousePosRect;
    
    	
    	SDL_Flip(screen);
    	SDL_FillRect(screen, 0, 0);
    }
    It does work if I take out these two lines:

    mousePosRect->x = mouseX;
    mousePosRect->y = mouseY;

    when i say work, i mean at runtime, not compile time. It compiles fine under all scenarios.
    Last edited by DavidP; 03-13-2004 at 12:32 PM.
    My Website

    "Circular logic is good because it is."

  2. #2
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738
    well i got it to work using a slightly different method of doing things, but still, if you know what was wrong with that old code, please do tell....i want to know
    My Website

    "Circular logic is good because it is."

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    I haven't tested this, but I think you are not filling the SDL_Rect completely. Not only to you have to fill in the rect.x and rect.y fields but also rect.w and rect.h

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sdl screen resize and redraw problem
    By mad_muppet in forum Game Programming
    Replies: 1
    Last Post: 08-09-2008, 09:55 PM
  2. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 06:20 AM
  3. Odd problem in main(), code won't proceed
    By aciarlillo in forum C++ Programming
    Replies: 1
    Last Post: 06-06-2005, 12:00 AM
  4. Homework help
    By Jigsaw in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2002, 05:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21