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\$
  • \$\begingroup\$ What error message do you get? \$\endgroup\$ – DMGregory Nov 29 '19 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 '19 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 '19 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 '19 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 '19 at 2:27
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.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Thanks , I solved it ! \$\endgroup\$ – Traistorm Nov 29 '19 at 3:19
  • \$\begingroup\$ Glad I could help! \$\endgroup\$ – Vaillancourt Nov 29 '19 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\$ – TomTsagk Nov 29 '19 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.