Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 85437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:05:21+00:00 2026-05-10T22:05:21+00:00

As I stated in this question , I am using SDL for a small

  • 0

As I stated in this question, I am using SDL for a small game I’m developing. Now I am having problems with SDL_DisplayFormatAlpha. I am trying to create a surface with an alpha channel from a PNG image. It was working before, but now that I’ve done some slight refactoring something got broken. I’ve narrowed it down to this constructor:

 Surface::Surface( tfilename file ) {     // initialize the surface data member to the image indicated by filename     SDL_Surface *tempSurface;     tempSurface = IMG_Load( file.c_str() );     if ( !tempSurface ) {         surface = NULL;         exit(1);     }     else {         surface = SDL_DisplayFormatAlpha( tempSurface );         //surface = tempSurface;     }     SDL_FreeSurface( tempSurface ); } 

This compiles just fine, but when I run it I get a Segmentation fault. The error reported by gdb:

 Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0xb79c16c0 (LWP 8089)] 0xb7e8b9a3 in SDL_DisplayFormatAlpha () from /usr/lib/libSDL-1.2.so.0 

The stack trace is as follows:

 #0  0xb7e8b9a3 in SDL_DisplayFormatAlpha () from /usr/lib/libSDL-1.2.so.0 #1  0x0804987e in Surface (this=0x804d060, file=@0xbfb20760) at Surface.cpp:16 #2  0x0804a159 in Image (this=0x804d038, x=0, y=0, file=@0xbfb207a0)     at Image.cpp:16 #3  0x0804a3de in Object (this=0x804d028, imageFile=@0xbfb207dc)     at Object.cpp:4 #4  0x080491cb in Application (this=0xbfb20810) at Application.cpp:8 #5  0x08048e0d in main () at main.cpp:5 

If I comment out surface = SDL_DisplayFormatAlpha( tempSurface ); and SDL_FreeSurface( tempSurface ); and uncomment surface = tempSurface; like so:

  Surface::Surface( tfilename file ) {     // initialize the surface data member to the image indicated by filename     SDL_Surface *tempSurface;     tempSurface = IMG_Load( file.c_str() );     if ( !tempSurface ) {         surface = NULL;         exit(1);     }     else {         //surface = SDL_DisplayFormatAlpha( tempSurface );         surface = tempSurface;     }     //SDL_FreeSurface( tempSurface ); }

Then it seems to work just fine. Can anyone tell me what’s going on? Actually, the transparency seems to work, too when I comment out SDL_DisplayFormatAlpha. Is that function only meant to be used with images that do not already have an alpha channel?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T22:05:22+00:00Added an answer on May 10, 2026 at 10:05 pm

    IMG_Load should handle transparent PNG’s automatically, as the end of your post notes. What is the actual exception/error being thrown? Your stack trace doesn’t show that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: WOW. This question is 12 years old now. As someone stated, it can
My question is Matlab related. There exist a fnct named nchoosek([vector],integer). By using this
basically it is a rehash of this question: Cannot connect using WebSockets, not changing
The current top-voted to this question states: Another one that's not so much a
On this question , there's an answer that states: You can use typedef to
This question is motivated by something I've lately started to see a bit too
In @mmalc's response to this question he states that In general you should not
Alright, I am going to state up front that this question may be too
Sorry, if this is a noobish question, but I'm just getting started with Rails
I haven't been able to find this explicitly stated anywhere yet, but a bunch

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.