0

In my project i have an Animator class, which has a method to load all sprites.

SDL_Texture*
Animator::CF_createImage_Load( SDL_Renderer* FP_renderer , std::string FV_path ,Uint8  FV_brC1,Uint8  FV_brC2,Uint8  FV_brC3, SDL_Window* window )
{
    SDL_Surface* loadSurface = IMG_Load(FV_path.c_str());

    SDL_Texture* texture = SDL_CreateTextureFromSurface( FP_renderer , loadSurface );

    SDL_SetTextureColorMod(texture, FV_brC1, FV_brC2, FV_brC3);
    SDL_SetTextureBlendMode( texture , SDL_BLENDMODE_ADD );

    return texture;

    SDL_FreeSurface( loadSurface );
    SDL_DestroyTexture( texture );
}

So if I run it within the IDE, it loads all sprites properly without any error. I just checked all pointers for debugging, all of them are ok, every image is shown properly as I said, but only within the IDE. If i build it and try to run the executable outside of the IDE ( in release or debug folder ), images are not shown at all.

There is one more thing. Font are loaded properly outside of the IDE, but Sprites aren't.

  • Are you using relative paths ("myfile.png" rather than "/mydata/myfile.png") to open the files and running afoul of a different initial working directory? – user4581301 Dec 09 '16 at 20:56
  • `char* sdlPath = SDL_GetBasePath(); string basePath = string(sdlPath);` I am using this code to get the full path, It works properly within the IDE. – László Lukács Dec 09 '16 at 21:07
  • I don't know if it is related, but you are leaking `loadSurface`, because the part after the return statement is never reached. Anyway, you could avoid the surface althogether by using `IMG_LoadTexture`. Also, what's the point of the window parameter? – Meyer Dec 09 '16 at 22:35
  • You're absolutely right, I will fix that leak. The window pointer is an unused var, I'll delete it, I used it before, but I forgot to deletet that. Thank you :) – László Lukács Dec 09 '16 at 22:47

0 Answers0