Segmentation fault using SDL with C ++ trying to fire up images

OK. I've got an interesting one here. I am working on a tetris clone (mainly to "level up" my skills). I was trying to refactor my code so that it is abstracted the way I wanted it to. So far it has only worked well, now I am getting a segmentation fault before any images can be activated. I've tried debugging it to no avail.

I have posted my working copy of the SVN project here .

This is just a small project, and someone with more knowledge than me and a good debugger will probably come up with this. The only dependency is SDL . Kudos to the person who can tell me what I am doing wrong.

Edit: As far as I can tell, what I have now and what I had before are logically the same, so I don't think that what I have now will cause a segmentation fault. Just run svn revert on your working copy, recompile and you should see it working ...

+1


source to share


3 answers


Look at lines 15 through 18 from Surface.cpp:

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

      

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



surface = tempSurface;

      

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

+4


source


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

I noticed this in the Output.cpp file:

display = new Surface();

      

You don't do anything. The constructor is empty for this. (the surface is not initialized).



Then, in Output :: initalize (), you do:

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

      

This looks like a problem. Surface :: surface has never been initialized. If you haven't found a solution, when I get home, I will look into it.

0


source


From what I understand, a segmentation fault occurs when you try to disable a ponter that is no longer available, or you try to change a constant value.

0


source







All Articles