Windows funnyness

I had a function that worked great in Linux. It returned a pointer to an
SDL_Surface. However, when I tried to compile the program under windows I
got the following warning:

SDL_Surface *image_load(char *filename) warning: image_load must return a
value.

Why will this compile on Linux and not on windows? Thanks.

  • Joel

Why will this compile on Linux and not on windows? Thanks.

Perhaps it can’t find the SDL.h header, so SDL_Surface isn’t defined, and
the warning is just misleading?

Just a guess.

–ryan.

I removed this function and the program compiled just fine. Still doesn’t
explain the problem…hmmmm…

  • Joel> ----- Original Message -----

From: Ryan C. Gordon [mailto:icculus@icculus.org]
Sent: Monday, August 06, 2001 4:21 PM
To: sdl at libsdl.org
Subject: Re: [SDL] windows funnyness

Why will this compile on Linux and not on windows? Thanks.

Perhaps it can’t find the SDL.h header, so SDL_Surface isn’t defined, and
the warning is just misleading?

Just a guess.

–ryan.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

The warning given (which, incidentally, shouldn’t stop it from compiling
unless you are using strict rules) means that there isn’t a “return” in that
function. Well, that’s what it should mean anyway!

Neil.> ----- Original Message -----

From: joel.dudley@developonline.com (Joel Dudley)
To:
Sent: Tuesday, August 07, 2001 12:32 AM
Subject: RE: [SDL] windows funnyness

I removed this function and the program compiled just fine. Still doesn’t
explain the problem…hmmmm…

  • Joel

-----Original Message-----
From: Ryan C. Gordon [mailto:icculus at clutteredmind.org]
Sent: Monday, August 06, 2001 4:21 PM
To: sdl at libsdl.org
Subject: Re: [SDL] windows funnyness

Why will this compile on Linux and not on windows? Thanks.

Perhaps it can’t find the SDL.h header, so SDL_Surface isn’t defined, and
the warning is just misleading?

Just a guess.

–ryan.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Ironicly there was indeed a return in that function. Like so.

return(screen);

Which was a pointer to SDL_Surface.> ----- Original Message -----

From: Neil Griffiths [mailto:n.griffiths@virgin.net]
Sent: Monday, August 06, 2001 4:49 PM
To: sdl at libsdl.org
Subject: Re: [SDL] windows funnyness

The warning given (which, incidentally, shouldn’t stop it from compiling
unless you are using strict rules) means that there isn’t a “return” in that
function. Well, that’s what it should mean anyway!

Neil.

----- Original Message -----
From: @Joel_Dudley (Joel Dudley)
To:
Sent: Tuesday, August 07, 2001 12:32 AM
Subject: RE: [SDL] windows funnyness

I removed this function and the program compiled just fine. Still doesn’t
explain the problem…hmmmm…

  • Joel

-----Original Message-----
From: Ryan C. Gordon [mailto:icculus at clutteredmind.org]
Sent: Monday, August 06, 2001 4:21 PM
To: sdl at libsdl.org
Subject: Re: [SDL] windows funnyness

Why will this compile on Linux and not on windows? Thanks.

Perhaps it can’t find the SDL.h header, so SDL_Surface isn’t defined, and
the warning is just misleading?

Just a guess.

–ryan.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Ironicly there was indeed a return in that function. Like so.

return(screen);

Which was a pointer to SDL_Surface.

…can we actually SEE this code, so we can stop guessing as to the
nature of the problem?

–ryan.

“Joel Dudley” <Joel.Dudley at DevelopOnline.com> wrote

Ironicly there was indeed a return in that function. Like so.

return(screen);

Which was a pointer to SDL_Surface.

my guess is there is some error case where nothing is
returned. need to look for this…

if(!everything_looks_good())
return;

need to make it a “return NULL;”

But that would make too much sense :stuck_out_tongue_winking_eye:

Load_and_format_bmp() gives me the problem.

  • Joel Dudley

    #include “SDL.h”
    #include <stdio.h>

SDL_Surface *load_bmp(char *fileName);

int main()
{
SDL_Surface *screen, *woods;
SDL_Event event;
SDLKey key;
int done = 0;

printf("Initializing SDL.\n");

/* Initialize defaults, Video and Audio */

if (SDL_Init(SDL_INIT_VIDEO) < 0) {
	printf("Could not initialize SDL: %s.\n", SDL_GetError());
	exit(-1);
}

printf("SDL Initialized.\n");

/* 
 * Initialize the display in a 640x480 8-bit palettized mode
 * requesting a software surface
 */

screen = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE);
if ( screen == NULL ) {
	fprintf(stderr, "Could'nt set 800x600 video mode: %s\n",

SDL_GetError());
exit(-1);
}

printf("Set 640x480 at %d bpp mode\n",

screen->format->BitsPerPixel);

/* Load graphics */
woods = load_and_format_bmp("Woods.bmp");

/* Palettized screen modes will have a default pallette
 *          * (a standard 8x8x4 color cube), but if the image is 
 *                   * palettized as well, we can use that palette

for
* * nicer color matching
* */
if ( woods->format->palette && screen->format->palette) {
SDL_SetColors(screen, woods->format->palette->colors, 0,
woods->format->palette->ncolors);
}

/* Blit onto the screen surface */
if(SDL_BlitSurface(woods, NULL, screen, NULL) != 0)
	fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());

SDL_UpdateRect(screen, 0, 0, woods->w, woods->h);

do {

while (SDL_PollEvent(&event) != 0) {
	if (event.type == SDL_KEYDOWN) {
		key = event.key.keysym.sym;

		if (key == SDLK_ESCAPE)
			done = 1;
	}
}
}
while (done == 0);

SDL_Quit();

return(0);

}

/* loads the BMP and formats it for the video surface */

SDL_Surface *load_and_format_bmp(char *fileName)
{
SDL_Surface *tmp, *surface;

/* Load the BMP file into a surface */
tmp = SDL_LoadBMP(fileName);
if (tmp == NULL) {
	fprintf(stderr, "Could'nt load %s: %s\n", fileName,

SDL_GetError());
return;
}

surface = SDL_DisplayFormat(tmp);
SDL_FreeSurface(tmp);

printf("Successfully loaded BMP file (%s)\n", fileName);

return(surface);

}
> ----- Original Message -----

From: Ryan C. Gordon [mailto:icculus@icculus.org]
Sent: Monday, August 06, 2001 6:28 PM
To: sdl at libsdl.org
Subject: RE: [SDL] windows funnyness

Ironicly there was indeed a return in that function. Like so.

return(screen);

Which was a pointer to SDL_Surface.

…can we actually SEE this code, so we can stop guessing as to the
nature of the problem?

–ryan.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

SDL_Surface *load_and_format_bmp(char *fileName)
{
SDL_Surface *tmp, *surface;

/* Load the BMP file into a surface */
tmp = SDL_LoadBMP(fileName);
if (tmp == NULL) {
fprintf(stderr, “Could’nt load %s: %s\n”, fileName, SDL_GetError());
return;
}
[…]

That “return” without a value in the “if (tmp == NULL)” block is the
problem. It’s not returning a value.

–ryan.

But that would make too much sense :stuck_out_tongue_winking_eye:

Load_and_format_bmp() gives me the problem.

  • Joel Dudley

[…]

/* Load graphics */
woods = load_and_format_bmp(“Woods.bmp”);

[…]

SDL_Surface *load_and_format_bmp(char *fileName)

Is that the entire file?

There appears to be nothing telling the compiler what
load_and_format_bmp() looks like before it’s used the first time, which
can cause all sorts of misinterpretations of the code. (C and C++
compilers are single pass compilers; ie they don’t know what’s ahead of
where they’re currently reading in your code.)

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |--------------------------------------> david at linuxdj.com -'On Tuesday 07 August 2001 18:21, you wrote:

Is the return nestled in an if/else or something? If
so, you might try adding another return at the end of
the function. Just a thought.

  • Ragan
    — Joel Dudley <Joel.Dudley at DevelopOnline.com> wrote:> Ironicly there was indeed a return in that function.

Like so.

return(screen);

Which was a pointer to SDL_Surface.

-----Original Message-----
From: Neil Griffiths [mailto:n.griffiths at virgin.net]

Sent: Monday, August 06, 2001 4:49 PM
To: sdl at libsdl.org
Subject: Re: [SDL] windows funnyness

The warning given (which, incidentally, shouldn’t
stop it from compiling
unless you are using strict rules) means that there
isn’t a “return” in that
function. Well, that’s what it should mean anyway!

Neil.


Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

Am Dienstag, 7. August 2001 18:21 schrieben Sie:

SDL_Surface *load_and_format_bmp(char *fileName)
{
SDL_Surface *tmp, *surface;

/* Load the BMP file into a surface */
tmp = SDL_LoadBMP(fileName);
if (tmp == NULL) {
fprintf(stderr, “Could’nt load %s: %s\n”, fileName,
SDL_GetError());
return;
}

Make the last line “return NULL” and it should compile fine.

Ciao,
Eike