Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualrip-off

Posted 20 January 2013 - 09:47 AM

"tempSurface" is NULL. Your call to apply_surface, which presumably ends up calling SDL_BlitSurface(), does not allocate a surface. Indeed, it cannot even if it tried - in C parameters are passed by value and cannot be modified by the callee:
void foo(int parameter) {
   parameter = 42; // Change is local to the function - parameter is a distinct copy of the caller's argument.
}

// Later
int x = 1;
printf("X: %d\n", x); // Will print "1"
foo(parameter);
printf("X: %d\n", x); // Will print "1"

This even applies to pointers (but not pointees):
void bar(int *pointer) {
    *pointer = 42; // Modifies pointee, will be visible to caller
    pointer = NULL; // Local change, not visible to caller
}

// Later
int x = 1;
int *p = &x;
printf("X: %d\n", x); // Will print "1"
printf("P: %p\n", p); // Will print some address in hex
bar(parameter);
printf("X: %d\n", x); // Will print "42"
printf("P: %p\n", p); // Will print the same hex as above
So SDL_BlitSurface() is not capable of modifying the pointer passed to it.

One option is to use SDL_CreateRGBSurface() in draw_wordbreak(). This is complicated by the fact that you'd need to know how big to make the surface. Another option is to draw directly to the screen in draw_wordbreak().

#2rip-off

Posted 20 January 2013 - 09:45 AM

"tempSurface" is NULL. Your call to apply_surface, which presumably ends up calling SDL_BlitSurface(), does not allocate a surface. Indeed, it cannot even if it tried - in C parameters are passed by value and cannot be modified by the callee:
void foo(int parameter) {   parameter = 42; // Change is local to the function - parameter is a distinct copy of the caller's argument.} int x = 1;printf("X: %d\n", x); // Will print "1"foo(parameter);printf("X: %d\n", x); // Will print "1"
This even applies to pointers (but not pointees):
void bar(int *pointer) {    *pointer = 42; // Modifies pointee, will be visible to caller    pointer = NULL; // Local change, not visible to caller}  int x = 1;int *p = &x;printf("X: %d\n", x); // Will print "1"printf("P: %p\n", p); // Will print some hexfoo(parameter); printf("X: %d\n", x); // Will print "42"printf("P: %p\n", p); // Will print the same hex as above
So SDL_BlitSurface() is not capable of modifying the pointer passed to it.

One option is to use SDL_CreateRGBSurface() in draw_wordbreak(). This is complicated by the fact that you'd need to know how big to make the surface. Another option is to draw directly to the screen in draw_wordbreak().

#1rip-off

Posted 20 January 2013 - 09:44 AM

"tempSurface" is NULL. Your call to apply_surface, which presumably ends up calling SDL_BlitSurface(), does not allocate a surface. Indeed, it cannot even if it tried - in C parameters are passed by value and cannot be modified by the callee:

void foo(int parameter) {
   parameter = 42; // Change is local to the function - parameter is a distinct copy of the caller's argument.
}
 
int x = 1;
printf("X: %d\n", x); // Will print "1"
foo(parameter);
printf("X: %d\n", x); // Will print "1"

 

This even applies to pointers (but not pointees):

void bar(int *pointer) {
    *pointer = 42; // Modifies pointee, will be visible to caller
    pointer = NULL; // Local change, not visible to caller
}
 
 
int x = 1;
int *p = &x;
printf("X: %d\n", x); // Will print "1"
printf("X: %p\n", p); // Will print some hex
foo(parameter);
 
printf("X: %d\n", x); // Will print "42"
printf("X: %p\n", p); // Will print the same hex as above

So SDL_BlitSurface() is not capable of modifying the pointer passed to it.

 

One option is to use SDL_CreateRGBSurface() in draw_wordbreak(). This is complicated by the fact that you'd need to know how big to make the surface. Another option is to draw directly to the screen in draw_wordbreak().


PARTNERS