[SDL] SDL_CreateSurfaceFrom crashes

Jonathan Dearborn grimfang4 at hotmail.com
Thu Aug 9 07:51:24 PDT 2007


Hey,
 
First, don't handle surfaces.  Only deal with pointers to surfaces.  If you kept using that line which dereferenced the surface pointer, you'd keep building up memory leakage.  There's no way to free those surfaces anymore.  You can take a lesson from Java's objects (You can never have a variable that IS an object, only a pointer to one).
 
SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, rmask, gmask, bmask, amask);
The "32" in this call means you're making a 32 bit surface.  It won't be auto-converted.  I'm pretty sure SDL_image leaves the conversion up to you as well.  If you load a big monochrome bmp, you don't want it to automatically take up several megabytes when it should take just a few kilobytes.
 
Sorry I don't have the time to work out a solution for you, but try this:
 
Base = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, rmask, gmask, bmask, amask);
SDL_SetAlpha(Base, SDL_SRCALPHA, 255);
SDL_FillRect(Base, NULL, 0x00000000);
I know if you blit something with per-pixel alpha onto this surface or use a putpixel with alpha function on it, it'll work correctly.  Per-surface alpha is disabled (in SDL_BlitSurface()) if you use per-pixel alpha, by the way.
 
 
Jonny D
 
 



> To: sdl at libsdl.org> From: kixdemp at gmail.com> Date: Thu, 9 Aug 2007 10:06:27 -0400> Subject: Re: [SDL] SDL_CreateSurfaceFrom crashes> > > Uh - why?> Because I'm dumb and thought it would cause conflicts with Lua... XD> > I made it a pointer and uppercased the 'B'.> > And this code:> > -----------------------> /* Create a 32-bit surface with the bytes of each pixel in R,G,B,A > order, as expected by OpenGL for textures */> > Uint32 rmask, gmask, bmask, amask;> > /* SDL interprets each pixel as a 32-bit number, so our masks must > depend on the endianness (byte order) of the machine */> #if SDL_BYTEORDER == SDL_BIG_ENDIAN> rmask = 0xff000000;> gmask = 0x00ff0000;> bmask = 0x0000ff00;> amask = 0x000000ff;> #else> rmask = 0x000000ff;> gmask = 0x0000ff00;> bmask = 0x00ff0000;> amask = 0xff000000;> #endif> > Base = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32,> rmask, gmask, bmask, amask);> -----------------------> > provides per-surface alpha (nothing is displayed at first, then if I > fill it with black my objects show over a black background, if I fill it > with 50% white then it shows the same thing but transparent), and I need > per-pixel alpha.> > Also, that same code, for some reason makes blitting slow... :-/> Maybe I'm missing some depth conversions? Doesn't SDL convert all > surfaces to screen depth upon creation? Or must I do that? What about > images loaded with IMG_Load(...)?> > Thanks all of you for helping this noob in despair!> > _______________________________________________> SDL mailing list> SDL at lists.libsdl.org> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
_________________________________________________________________
Learn. Laugh. Share. Reallivemoms is right place!
http://www.reallivemoms.com?ocid=TXT_TAGHM&loc=us
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20070809/e5ba33fc/attachment.htm 


More information about the SDL mailing list