Your code is fine having tested it on my system. I suspect it is one of the following:
The texture you are trying to load is not in the correct directory. This would cause the application to fail when trying to load the texture. The texture, according to your code, should reside in the same folder as your VC++ Project file. You can put it in other directories, you just need to specify a path when loading it.
You don't have the SDL and SDL_image DLL files in the same directory as your executable. This will cause the application to fail during the initialisation calls for SDL and SDL_image. These are the DLL's which I had in in the directory (I tend to include all the image type libs but if you are only ever use one image format you can just have that one):
- libjpeg-9.dll
- libpng16-16.dll
- libtiff-5.dll
- libwebp-4.dll
- SDL2.dll
- SDL2_image.dll
It should be easy to find where it is failing by stepping through the code one line at a time.
The only other comment I would make is that loadmedia()
returns a bool so you should probably change if (loadMedia() == NULL)
to just if (!loadMedia())