问题SDL_DisplayFormatAlpha(c++)
-
19-08-2019 - |
题
正如我在 这个问题, 我使用SDL为一个小游戏我发展。现在我有问题SDL_DisplayFormatAlpha.我试图建立一个表面上有一个阿尔法渠道从一个新的图像。这是工作之前,但现在,我已经做过一些轻微的重构的东西拿到了破坏。我把范围缩小到这个构造:
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 );
}
本汇编只是好的,但当我运行了它,我得到一个分割的错误。报告的错误库:
Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0xb79c16c0 (LWP 8089)] 0xb7e8b9a3 in SDL_DisplayFormatAlpha () from /usr/lib/libSDL-1.2.so.0
堆栈如下:
#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
如果我出的评论 surface = SDL_DisplayFormatAlpha( tempSurface );
和 SDL_FreeSurface( tempSurface );
和注释 surface = tempSurface;
像这样:
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 );
}
然后,它似乎只是罚款。谁能告诉我这是怎么回事?实际上,透明度似乎运作,也当我出评论SDL_DisplayFormatAlpha.是的功能只是意味着要使用的图像,已经没有一个阿尔法渠道?
解决方案
IMG_Load应当处理透明PNG是自动结束后注释。什么是实际的异常情况/差错被扔?你堆痕并不显示。
其他提示
如果你读链接(相关的功能):
"你得叫SDL_Init前使用的SDL_DisplayFormat功能。如果你不要,你的程序将崩溃,一个访问的违反。"
可能这就是你的问题吗?
不隶属于 StackOverflow