Jump to content

  • Log In with Google      Sign In   
  • Create Account

[SDL] Pixel access segfault


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Vaclav   Members   -  Reputation: 137

Like
0Likes
Like

Posted 03 September 2012 - 05:10 AM

I try to access a pixel on a surface with the getpixel function from SDL's help:
http://sdl.beuc.net/...ki/Pixel_Access

It works for 32bit surfaces, but gives segfault for 8bit surfaces at line return *p; after case 1:.
If I change that line to return *(Uint32*)p; I don't get segfault, but when I try to use the returned value by either SDL_GetRGB or SDL_GetRGBA, I get segfault, so the returned value is obviously incorrect. (However with the 32bit surface these functions work, so it's not me using them wrong way.)
I haven't tested for 16 or 24 bit surfaces.
Aslo the 32bit surface was loaded from a png with per pixel alpha, but the 8bit surface was loaded from a bmp with colorkey alpha, but I don't think this matters.
Any idea how to get it working?

Edited by Vaclav, 04 September 2012 - 01:57 AM.


Sponsor:

#2 Geometrian   Crossbones+   -  Reputation: 1602

Like
0Likes
Like

Posted 03 September 2012 - 03:47 PM

I have used that exact code myself before using memory fences with no problems.

Are you sure you're accessing at valid pixels? E.g., the top left pixel is (0,0), NOT (1,1). Accessing a 512x512 image at location (512,512) could cause a segfault.
And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.

#3 Vaclav   Members   -  Reputation: 137

Like
0Likes
Like

Posted 04 September 2012 - 01:56 AM

Yes, I'm sure because exactly the same code works for 32 bit surfaces. If would try to access with invalid parameters, it would cause segfault for 32 bit surafces as well.

#4 TomVD   Members   -  Reputation: 186

Like
0Likes
Like

Posted 07 September 2012 - 07:02 AM

Hmm, an 8bit surface is not stored as RGB values, but as indexes to a palette. The getRGB is using that index to look up the RGB value in your palette. Maybe you didn't create that palette data which might explain the segfault?

We used 8 bit surfaces and palettes in our retro game remake project, but it didn't give use anything but head-aches. Unless you are coding for a very old device with limited memory, or want to give yourself a challenge, I personally would suggest NOT using 8 bit surfaces.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS