SDL_CreateRGBSurface() crash with SDL_HWSURFACE... why?

Greets, I’ve encountered an odd error with SDL_CreateRGBSurface() where
the app will /always/ crash if SDL_HWSURFACE is passed (if the app is in
fullscreen mode - hardware acceleration doesn’t occur in windowed mode,
yes?)

The surface created by SDL_SetVideoMode has already had SDL_HWSURFACE |
SDL_HWPALETTE | SDL_FULLSCREEN passed to it

Unfortunately, I only receive the messages
"Fatal signal: Bus Error (SDL Parachute Deployed)

buggy.app has exited with status 246."
in Project Builder, and SDL_GetError() returns NULL.

Any suggestions as to why? Would this be caused by having an
under-powered graphics card (only the usual 8Mb fitted to the 2000-ish
era iMacs; but which can’t store two 640x480 32bit images??? That’s only
~2Mb uncompressed???)

Maybe the source to the section in question will help, but I’ve already
re-coded it several times with no change to the app.

if(( theBufferSurface = SDL_CreateRGBSurface((( SDL_SWSURFACE *
( thePrefs.useHardwareAcceleration ^ 1 )) |
( SDL_HWSURFACE * thePrefs.useHardwareAcceleration )),
thePrefs.width,
thePrefs.height,
kPrefs_default__depth,
theSurface->format->Rmask,
theSurface->format->Gmask,
theSurface->format->Bmask,
theSurface->format->Amask )) == NULL )

Mark

“Opportunity is missed by most people because it is dressed in overalls
and looks like work.”
~Thomas Edison
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: text/enriched
Size: 1452 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20031221/8fd7a49e/attachment.bin

It’s not possible to palette a 32bit image in hardware.

This is in the SDL source from SetVideoMode

/* There's no palette in > 8 bits-per-pixel mode */
if ( video_bpp > 8 ) {
	flags &= ~SDL_HWPALETTE;

So you are out of luck for a 32bit palette.

Tyler

Mark Bishop wrote:> Greets, I’ve encountered an odd error with SDL_CreateRGBSurface() where

the app will /always/ crash if SDL_HWSURFACE is passed (if the app is in
fullscreen mode - hardware acceleration doesn’t occur in windowed mode,
yes?)

The surface created by SDL_SetVideoMode has already had SDL_HWSURFACE |
SDL_HWPALETTE | SDL_FULLSCREEN passed to it

Unfortunately, I only receive the messages
"Fatal signal: Bus Error (SDL Parachute Deployed)

buggy.app has exited with status 246."
in Project Builder, and SDL_GetError() returns NULL.

Any suggestions as to why? Would this be caused by having an
under-powered graphics card (only the usual 8Mb fitted to the 2000-ish
era iMacs; but which can’t store two 640x480 32bit images??? That’s only
~2Mb uncompressed???)

Maybe the source to the section in question will help, but I’ve already
re-coded it several times with no change to the app.

if(( theBufferSurface = SDL_CreateRGBSurface((( SDL_SWSURFACE * (
thePrefs.useHardwareAcceleration ^ 1 )) |
( SDL_HWSURFACE * thePrefs.useHardwareAcceleration )),
thePrefs.width,
thePrefs.height,
kPrefs_default__depth,
theSurface->format->Rmask,
theSurface->format->Gmask,
theSurface->format->Bmask,
theSurface->format->Amask )) == NULL )

Mark

“Opportunity is missed by most people because it is dressed in overalls
and looks like work.”
~Thomas Edison

I would not use your method to get flags, partly because it’s difficult
to read and partly because multiplying a flag is a bad idea. It’d be
fine as long as useHardwareAcceleration is 0 or 1. But if later, for
example, you set useHardwareAcceleration to a function’s return value,
maybe it would be 2, or -1. For saftey and aesthetics, i’d use the
ternary operator:
(thePrefs.useHardwareAcceleration ? SDL_HWSURFACE : SDL_SWSURFACE)

The surface created by SDL_SetVideoMode has already had SDL_HWSURFACE |
SDL_HWPALETTE | SDL_FULLSCREEN passed to it

Do you really want a paletted hardware surface?

If you can write a minimal example that causes the crash, someone might
be able to fix it (or at least identify what you’re doing wrong, if the
crash isn’t SDL’s fault).

if(( theBufferSurface = SDL_CreateRGBSurface((( SDL_SWSURFACE * (
thePrefs.useHardwareAcceleration ^ 1 )) |
( SDL_HWSURFACE * thePrefs.useHardwareAcceleration )),

What?

If you want people to go near your code, write sensibly. Don’t do
evil tricks that obfuscate the code.

int flags = 0;
if(thePrefs.useHardwareAcceleration)
flags |= SDL_HWSURFACE;
else
flags |= SDL_SWSURFACE;
theBufferSurface = SDL_CreateRGBSurface( flags, … );
if( theBufferSurface == NULL )

If people can read your code, they’ll be more likely to help you out. :)On Sun, Dec 21, 2003 at 01:58:53PM +0000, Mark Bishop wrote:


Glenn Maynard

Greets,

If you can write a minimal example that causes the crash, someone might
be able to fix it (or at least identify what you’re doing wrong, if the
crash isn’t SDL’s fault).

A short example of the crashing code… any suggestions? I quickly
re-coded those parts you labeled obfuscated :slight_smile:

#include <SDL/SDL.h>
#include “error_log.h”

#define kPrefs_default__depth 32

typedef struct prefs_struct
{
Uint8 fullscreen,
useHardwareAcceleration;
Uint16 width,
height;
}
prefs_type;

prefs_type thePrefs;

Uint8 errorLogInitialised = 0;

SDL_Surface *theSurface = NULL,
*theBufferSurface = NULL;

Sint8 InitialiseVideo( void );

int main( int argc,
char *argv[] )
{
SDL_Event event;
SDL_Init( SDL_INIT_VIDEO );
thePrefs.fullscreen = 1;
thePrefs.width = 640;
thePrefs.height = 480;
thePrefs.useHardwareAcceleration = 0;
if( InitialiseVideo() != 0 )
{
return 0;
}
while( SDL_PollEvent( &event ))
{ ; }
SDL_Delay( 5000 );
SDL_Quit();
return 0;
}

Sint8 InitialiseVideo( void )
{
Uint32 flags;

flags = 0;
if( thePrefs.fullscreen )
{
flags |= SDL_FULLSCREEN;
}
if( thePrefs.useHardwareAcceleration )
{
flags |= SDL_HWSURFACE;
}
else
{
flags |= SDL_SWSURFACE;
}
if(( theSurface = SDL_SetVideoMode( thePrefs.width,
thePrefs.height,
kPrefs_default__depth,
flags )) == NULL )
{
LogError( kSDL_error_call, “couldn’t initialise the surface with
the default prefs” );
return -1;
}
LogError( kNo_error_call, “got this far” );
flags = 0;
if( thePrefs.useHardwareAcceleration )
{
flags |= SDL_HWSURFACE;
}
else
{
flags |= SDL_SWSURFACE;
}
if(( theBufferSurface = SDL_CreateRGBSurface( flags,
thePrefs.width,
thePrefs.height,
kPrefs_default__depth,
theSurface->format->Rmask,
theSurface->format->Gmask,
theSurface->format->Bmask,
theSurface->format->Amask )) == NULL )
{
LogError( kSDL_error_call, “couldn’t initialise the buffer surface
with the default prefs” );
return -1;
}
LogError( kNo_error_call, “got a little further” );
if( !thePrefs.fullscreen )
{
SDL_WM_SetCaption( “title”, “title” );
}
return 0;
}

if(( theBufferSurface = SDL_CreateRGBSurface((( SDL_SWSURFACE * (
thePrefs.useHardwareAcceleration ^ 1 )) |
( SDL_HWSURFACE * thePrefs.useHardwareAcceleration )),
What?

If you want people to go near your code, write sensibly. Don’t do
evil tricks that obfuscate the code.

int flags = 0;
if(thePrefs.useHardwareAcceleration)
flags |= SDL_HWSURFACE;
else
flags |= SDL_SWSURFACE;
theBufferSurface = SDL_CreateRGBSurface( flags, … );
if( theBufferSurface == NULL )

If people can read your code, they’ll be more likely to help you out. :slight_smile:


Glenn Maynard

“Opportunity is missed by most people because it is dressed in overalls
and looks like work.”
~Thomas Edison
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: text/enriched
Size: 3127 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20031222/7f3d0609/attachment.bin

Greets, to reply to myself with a little more information on the error;
the error only occurs if SDL_HWSURFACE is passed to both
SDL_SetVideoMode and SDL_CreateRGBSurface; if either one has
SDL_SWSURFACE passed instead, the crash doesn’t occur. Still unable to
determine why it crashes though… any suggestions people?

Thanks,

MarkOn Monday, December 22, 2003, at 09:29  am, Mark Bishop wrote:

Greets,

If you can write a minimal example that causes the crash, someone might
be able to fix it (or at least identify what you’re doing wrong, if the
crash isn’t SDL’s fault).

A short example of the crashing code… any suggestions? I quickly
re-coded those parts you labeled obfuscated :slight_smile:

#include <SDL/SDL.h>
#include “error_log.h”

#define kPrefs_default__depth 32

typedef struct prefs_struct
{
Uint8 fullscreen,
useHardwareAcceleration;
Uint16 width,
height;
}
prefs_type;

prefs_type thePrefs;

Uint8 errorLogInitialised = 0;

SDL_Surface *theSurface = NULL,
*theBufferSurface = NULL;

Sint8 InitialiseVideo( void );

int main( int argc,
char *argv[] )
{
SDL_Event event;
SDL_Init( SDL_INIT_VIDEO );
thePrefs.fullscreen = 1;
thePrefs.width = 640;
thePrefs.height = 480;
thePrefs.useHardwareAcceleration = 0;
if( InitialiseVideo() != 0 )
{
return 0;
}
while( SDL_PollEvent( &event ))
{ ; }
SDL_Delay( 5000 );
SDL_Quit();
return 0;
}

Sint8 InitialiseVideo( void )
{
Uint32 flags;

flags = 0;
if( thePrefs.fullscreen )
{
flags |= SDL_FULLSCREEN;
}
if( thePrefs.useHardwareAcceleration )
{
flags |= SDL_HWSURFACE;
}
else
{
flags |= SDL_SWSURFACE;
}
if(( theSurface = SDL_SetVideoMode( thePrefs.width,
thePrefs.height,
kPrefs_default__depth,
flags )) == NULL )
{
LogError( kSDL_error_call, “couldn’t initialise the surface with
the default prefs” );
return -1;
}
LogError( kNo_error_call, “got this far” );
flags = 0;
if( thePrefs.useHardwareAcceleration )
{
flags |= SDL_HWSURFACE;
}
else
{
flags |= SDL_SWSURFACE;
}
if(( theBufferSurface = SDL_CreateRGBSurface( flags,
thePrefs.width,
thePrefs.height,
kPrefs_default__depth,
theSurface->format->Rmask,
theSurface->format->Gmask,
theSurface->format->Bmask,
theSurface->format->Amask )) == NULL )
{
LogError( kSDL_error_call, “couldn’t initialise the buffer surface
with the default prefs” );
return -1;
}
LogError( kNo_error_call, “got a little further” );
if( !thePrefs.fullscreen )
{
SDL_WM_SetCaption( “title”, “title” );
}
return 0;
}

if(( theBufferSurface = SDL_CreateRGBSurface((( SDL_SWSURFACE * (
thePrefs.useHardwareAcceleration ^ 1 )) |
( SDL_HWSURFACE * thePrefs.useHardwareAcceleration )),
What?

If you want people to go near your code, write sensibly. Don’t do
evil tricks that obfuscate the code.

int flags = 0;
if(thePrefs.useHardwareAcceleration)
flags |= SDL_HWSURFACE;
else
flags |= SDL_SWSURFACE;
theBufferSurface = SDL_CreateRGBSurface( flags, … );
if( theBufferSurface == NULL )

If people can read your code, they’ll be more likely to help you
out. :slight_smile:


Glenn Maynard

“Opportunity is missed by most people because it is dressed in overalls
and looks like work.”
~Thomas Edison

“Text processing has made it possible to right-justify any idea, even
one which cannot be justified on any other grounds.”
~J. Finnegan
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: text/enriched
Size: 3698 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20031223/9a7c4057/attachment.bin

Greets, I’ve encountered an odd error with SDL_CreateRGBSurface() where
the app will /always/ crash if SDL_HWSURFACE is passed (if the app is in
fullscreen mode - hardware acceleration doesn’t occur in windowed mode,
yes?)

Does it actually crash inside SDL_CreateRGBSurface()? Are you able to run
the code under the debugger to find out where it’s crashing? If not, please
post a link to a complete buildable example with data so we can reproduce it.

Thanks,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Greets, I included the source to a compile-able example of the crashing
code in an earlier email; I’ve reproduced the source below.

#include <SDL/SDL.h>
#include “error_log.h”

#define kPrefs_default__depth 32

typedef struct prefs_struct
{
Uint8 fullscreen,
useHardwareAcceleration;
Uint16 width,
height;
}
prefs_type;

prefs_type thePrefs;

Uint8 errorLogInitialised = 0;

SDL_Surface *theSurface = NULL,
*theBufferSurface = NULL;

Sint8 InitialiseVideo( void );

int main( int argc,
char *argv[] )
{
SDL_Event event;
SDL_Init( SDL_INIT_VIDEO );
thePrefs.fullscreen = 1;
thePrefs.width = 640;
thePrefs.height = 480;
thePrefs.useHardwareAcceleration = 0;
if( InitialiseVideo() != 0 )
{
return 0;
}
while( SDL_PollEvent( &event ))
{ ; }
SDL_Delay( 5000 );
SDL_Quit();
return 0;
}

Sint8 InitialiseVideo( void )
{
Uint32 flags;

flags = 0;
if( thePrefs.fullscreen )
{
flags |= SDL_FULLSCREEN;
}
if( thePrefs.useHardwareAcceleration )
{
flags |= SDL_HWSURFACE;
}
else
{
flags |= SDL_SWSURFACE;
}
if(( theSurface = SDL_SetVideoMode( thePrefs.width,
thePrefs.height,
kPrefs_default__depth,
flags )) == NULL )
{
//LogError( kSDL_error_call, “couldn’t initialise the surface with
the default prefs” );
return -1;
}
//LogError( kNo_error_call, “got this far” );
flags = 0;
if( thePrefs.useHardwareAcceleration )
{
flags |= SDL_HWSURFACE;
}
else
{
flags |= SDL_SWSURFACE;
}
if(( theBufferSurface = SDL_CreateRGBSurface( flags,
thePrefs.width,
thePrefs.height,
kPrefs_default__depth,
theSurface->format->Rmask,
theSurface->format->Gmask,
theSurface->format->Bmask,
theSurface->format->Amask )) == NULL )
{
//LogError( kSDL_error_call, “couldn’t initialise the buffer
surface with the default prefs” );
return -1;
}
//LogError( kNo_error_call, “got a little further” );
if( !thePrefs.fullscreen )
{
SDL_WM_SetCaption( “title”, “title” );
}
return 0;
}

I’ve also tested by removing the call to SDL_CreateSDLSurface
( SDL_HWSURFACE, … ); without that call (or with SDL_SWSURFACE passed
instead) the code runs fine.

Anyway, thanks very much,

MarkOn Tuesday, December 23, 2003, at 02:43  pm, Sam Lantinga wrote:

Greets, I’ve encountered an odd error with SDL_CreateRGBSurface() where
the app will /always/ crash if SDL_HWSURFACE is passed (if the app is
in
fullscreen mode - hardware acceleration doesn’t occur in windowed mode,
yes?)

Does it actually crash inside SDL_CreateRGBSurface()? Are you able to
run
the code under the debugger to find out where it’s crashing? If not,
please
post a link to a complete buildable example with data so we can
reproduce it.

Thanks,
-Sam Lantinga, Software Engineer, Blizzard Entertainment


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: text/enriched
Size: 3220 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20031223/0cdbbeb8/attachment.bin

Greets, just included a couple of emails I sent to the list near
Christmas, but never got a solution to…

Thanks,

Mark

Greets, I’ve encountered an odd error with SDL_CreateRGBSurface() where
the app will /always/ crash if SDL_HWSURFACE is passed (if the app is in
fullscreen mode - hardware acceleration doesn’t occur in windowed mode,
yes?)

The surface created by SDL_SetVideoMode has already had SDL_HWSURFACE |
SDL_HWPALETTE | SDL_FULLSCREEN passed to it

Unfortunately, I only receive the messages
"Fatal signal: Bus Error (SDL Parachute Deployed)

buggy.app has exited with status 246."
in Project Builder, and SDL_GetError() returns NULL.

Any suggestions as to why? Would this be caused by having an
under-powered graphics card (only the usual 8Mb fitted to the 2000-ish
era iMacs; but which can’t store two 640x480 32bit images??? That’s only
~2Mb uncompressed???)

Greets, to reply to myself with a little more information on the error;
the error only occurs if SDL_HWSURFACE is passed to both
SDL_SetVideoMode and SDL_CreateRGBSurface; if either one has
SDL_SWSURFACE passed instead, the crash doesn’t occur. Still unable to
determine why it crashes though… any suggestions people?

#include <SDL/SDL.h>
#include “error_log.h”

#define kPrefs_default__depth 32

typedef struct prefs_struct
{
Uint8 fullscreen,
useHardwareAcceleration;
Uint16 width,
height;
}
prefs_type;

prefs_type thePrefs;

Uint8 errorLogInitialised = 0;

SDL_Surface *theSurface = NULL,
*theBufferSurface = NULL;

Sint8 InitialiseVideo( void );

int main( int argc,
char *argv[] )
{
SDL_Event event;
SDL_Init( SDL_INIT_VIDEO );
thePrefs.fullscreen = 1;
thePrefs.width = 640;
thePrefs.height = 480;
thePrefs.useHardwareAcceleration = 0;
if( InitialiseVideo() != 0 )
{
return 0;
}
while( SDL_PollEvent( &event ))
{ ; }
SDL_Delay( 5000 );
SDL_Quit();
return 0;
}

Sint8 InitialiseVideo( void )
{
Uint32 flags;

flags = 0;
if( thePrefs.fullscreen )
{
flags |= SDL_FULLSCREEN;
}
if( thePrefs.useHardwareAcceleration )
{
flags |= SDL_HWSURFACE;
}
else
{
flags |= SDL_SWSURFACE;
}
if(( theSurface = SDL_SetVideoMode( thePrefs.width,
thePrefs.height,
kPrefs_default__depth,
flags )) == NULL )
{
//LogError( kSDL_error_call, “couldn’t initialise the surface with
the default prefs” );
return -1;
}
//LogError( kNo_error_call, “got this far” );
flags = 0;
if( thePrefs.useHardwareAcceleration )
{
flags |= SDL_HWSURFACE;
}
else
{
flags |= SDL_SWSURFACE;
}
if(( theBufferSurface = SDL_CreateRGBSurface( flags,
thePrefs.width,
thePrefs.height,
kPrefs_default__depth,
theSurface->format->Rmask,
theSurface->format->Gmask,
theSurface->format->Bmask,
theSurface->format->Amask )) == NULL )
{
//LogError( kSDL_error_call, “couldn’t initialise the buffer
surface with the default prefs” );
return -1;
}
//LogError( kNo_error_call, “got a little further” );
if( !thePrefs.fullscreen )
{
SDL_WM_SetCaption( “title”, “title” );
}
return 0;
}
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: text/enriched
Size: 3320 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20040109/56f1e236/attachment.bin

Mark Bishop wrote:

Greets, just included a couple of emails I sent to the list near
Christmas, but never got a solution to…

Maybe you could tell us what platform this is on…
I tried your program on linux/x11 and it doesn’t crash.

Stephane

Also reports in good from Windows; with MSVC++ 7, MSVC++6, and MinGW.
I even tried changing the value of the useHardwareAcceleration thing (which
in the posted code made it not use the SDL_HWSURFACE flag that was stated to
be the problem). You might ant to try this too, Stephane.

Mark: You had a bunch of stuff relating to Macs, but I can’t discern whether
it’s OSX or Classic. Can you elaborate on which OS you’re experiencing the
problem with?

  • Silicon> ----- Original Message -----

From: stephane.marchesin@wanadoo.fr (Stephane Marchesin)
To:
Sent: Friday, January 09, 2004 1:03 PM
Subject: Re: [SDL] SDL_CreateRGBSurface() crash with SDL_HWSURFACE… why?

Mark Bishop wrote:

Greets, just included a couple of emails I sent to the list near
Christmas, but never got a solution to…

Maybe you could tell us what platform this is on…
I tried your program on linux/x11 and it doesn’t crash.

Stephane


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


Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.552 / Virus Database: 344 - Release Date: 12/15/2003

Mark: You had a bunch of stuff relating to Macs, but I can’t discern
whether
it’s OSX or Classic. Can you elaborate on which OS you’re experiencing
the
problem with?

Sorry, I should’ve pointed this out; Mac OS X (10.1.5)

Thanks,

Mark

Mark: You had a bunch of stuff relating to Macs, but I can’t discern
whether
it’s OSX or Classic. Can you elaborate on which OS you’re experiencing
the
problem with?

Sorry, I should’ve pointed this out; Mac OS X (10.1.5)

Try in the latest CVS code, some things might have been fixed:
http://www.libsdl.org/cvs.php

See ya!
-Sam Lantinga, Software Engineer, Blizzard Entertainment