1

The problem comes from the "IMG_load" fonction of the SDL_image, with language C. It raises no error during execution, but when it comes to the line

SDL_Surface* image1 = IMG_Load("image.bmp");

the function returns a data that I can't use: for instance, SDL_BlitSurface(image1, NULL, screen, &position) won't do anything. However, it works fine when using the function SDL_LoadBMP. I have used the debugger to try to understand the difference between the data returned by the two functions:

Here is what IMG_Load("image.bmp") returns:

{ //Doesn't work
      flags = 0, 
      format = 0x3c07c0, 
      w = 40, 
      h = 40, 
      pitch = 120, 
      pixels = 0x3c07f0, 
      offset = 0, 
      hwdata = 0x0, 
      clip_rect = {
          x = 0, 
          y = 0, 
          w = 0, 
          h = 0
      }, 
      unused1 = 0, 
      locked = 40, 
      map = 0x28, 
      format_version = 3939000, 
      refcount = 1
}

And here is what SDL_LoadBMP("image.bmp") returns:

{ //Works fine
    flags = 0,
    hwdata = 0x0, 
    clip_rect = {
        x = 0, 
        y = 0, 
        w = 40, 
        h = 40
    }, 
    unused1 = 0, 
    locked = 0, 
    map = 0x3458e8, 
    format_version = 7, 
    refcount = 1
}

(Note that the image is the same, and it is a 40x40px square).

Why can't I use SDL_BlitSurface on a SDL_Surface returned by the function IMG_Load?

edit: you also have to know that this is the first time a function from the SDL_Image package is used in the program.

Hellstahl
  • 11
  • 1
  • 4
  • What versions of SDL and SDL_image are you using? Have you called `*_Init` functions for both libraries? – keltar Jun 01 '15 at 06:13
  • I am using the version 1.2.15 of SDL, and SDL_image 1.2.12. I have called the *_Init functions and checked that both *_Init functions are doing their jobs as they should. – Hellstahl Jun 01 '15 at 08:39
  • 2
    Well this [minimal example](http://pastebin.com/HNNCw8Fj) works fine for me. If it isn't, verify your file is ok and libs/includes are exactly as you want them to be (with `ldd` and by examining compiler/linker invocation lines). If you still unable to determine cause, please add minimal example, compilation line and ldd output to the question. – keltar Jun 01 '15 at 09:00
  • Thank you very much, it works fine now. The minimal example has been really useful. I believe the problem came from the `#include "SDL.h"` and such. I was using `#include "SDL/SDL.h"`. To make the minimal example work, I had to copy the files in C:\Program Files (x86)\CodeBlocks\share\CodeBlocks\SDL-1.2.15\include\SDL to C:\Program Files (x86)\CodeBlocks\share\CodeBlocks\SDL-1.2.15\include. When I came back to my program, all was then well. Thank you again! – Hellstahl Jun 01 '15 at 09:55

0 Answers0