0
\$\begingroup\$

I have three image files, one is Techs.png, one is Techs.gif and one is Techs.bmp. I have used SDL_image 2.0.5 and SDL 2. When I load the image of Techs.gif and Techs.bmp, there is no error, but when I load the image of Techs.png. SDL_Surface*Surface=IMG_Load("Techs.png"), an error occurs, I cannot load this image and Surface always returns NULL, I am using Visual Studio 2019. Can someone help me, thanks.

\$\endgroup\$
11
  • \$\begingroup\$ What error message do you get? \$\endgroup\$
    – DMGregory
    Nov 29, 2019 at 1:24
  • \$\begingroup\$ That Error is Surface of this Image is always returns NULL and i cann't load it to the screen. \$\endgroup\$
    – Traistorm
    Nov 29, 2019 at 1:41
  • 1
    \$\begingroup\$ Ok, what error message do you get? Or are you meaning that you don't get an error message, that the returned value is always nullptr? \$\endgroup\$
    – Vaillancourt
    Nov 29, 2019 at 1:51
  • 1
    \$\begingroup\$ Also, can we assume that you read the doc and used IMG_GetError() to get the error message? \$\endgroup\$
    – Vaillancourt
    Nov 29, 2019 at 1:57
  • 1
    \$\begingroup\$ "Failed loading libpng16-16.dll: The specified module could not be found." Did you also copy libpng16-16.dll? \$\endgroup\$
    – Vaillancourt
    Nov 29, 2019 at 2:27

1 Answer 1

0
\$\begingroup\$

When in doubt, make sure you read the documentation for the functions you use. There are sometimes hidden gems and very useful tips there.

In this case, we can see that there is a function called IMG_GetError() which should be used to retrieve a human readable message of the error you got.

Using this, you'll be able to narrow down the possible sources of issues.

\$\endgroup\$
2
  • \$\begingroup\$ Glad I could help! \$\endgroup\$
    – Vaillancourt
    Nov 29, 2019 at 3:24
  • \$\begingroup\$ @Traistorm For future users, it might be helpful to mention what the problem was. I imagine its that SDL does not support loading png files by default and you had to use the SDL_Image extention? It would be good for this to be mentioned somewhere. \$\endgroup\$ Nov 29, 2019 at 10:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .