$ cat baz.cpp
#include <iostream>
usingnamespace std;
void foo ( ) {
int *p = 0;
*p = 0; // boom
}
void bar ( ) {
int a = 2;
foo();
}
int main ( ) {
bar();
}
# compile with -g for debug goodness
$ g++ -g baz.cpp
$ gdb -q ./a.out
Reading symbols from ./a.out...done.
(gdb) run
Starting program: ./a.out
Program received signal SIGSEGV, Segmentation fault.
0x00000000004006c6 in foo () at baz.cpp:6
6 *p = 0; // boom
(gdb) bt
#0 0x00000000004006c6 in foo () at baz.cpp:6
#1 0x00000000004006e3 in bar () at baz.cpp:11
#2 0x00000000004006ef in main () at baz.cpp:15
(gdb) up
#1 0x00000000004006e3 in bar () at baz.cpp:11
11 foo();
(gdb) print a
$1 = 2
(gdb)
So now you compile your program with the -g flag, run it in the debugger and show us a stack trace and the value(s) of interesting variables.
Your indentation is a mess, but it looks like you can get to SDL_FreeSurface( textsurface ); with a NULL pointer.
Are you calling it from the main thread?
Is the TTF_Font object correctly initialized and is its pointer valid?
Is the SDL_Renderer object correctly initialized and is its pointer valid?
Does the const char pointer point to a valid C string in readable memory?
By the way, there's no reason for textsurface and mytexture to be class members. They should be local variables to prevent the function from causing undesirable side-effects.