Segmentation fault using SDL with C++, trying to Blit images

跟風遠走 提交于 2019-12-04 18:16:37

Look at line 15 to 18 of Surface.cpp:

    surface = SDL_DisplayFormatAlpha( tempSurface );
    surface = tempSurface;
}
SDL_FreeSurface( tempSurface );

I assume it segfaults because when you use this surface later, you are actually operating on tempSurface because of this line:

surface = tempSurface;

and not the surface returned by SDL_DisplayFormatAlpha(). Since you free tempSurface, surface is now pointing to invalid memory. To fix, simply remove the second line in the else block.

I don't have SDL installed on my machine, but after looking through the code.

I noticed this in the Output.cpp file:

display = new Surface();

You do nothing. The constructor for this is empty. (surface is not initialized).

Then in Output::initalize() you do:

display->surface = SDL_SetVideoMode( 800, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF );

This looks like the issue Surface::surface was never actually initialized. If you haven't found the solution, when i get home i'll digg into it.

As far as I understand, a segmentation fault happens when you are trying to mnaipulate a ponter which is no longer available, or you are trying to change a constant's value.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!