Failing to load a png image in SDL2 - c++

I am trying to load PNG image, but it always ends in an error. I was first trying to use SDL's SDL_LoadBMP, but since that dind't work, I downloaded SDL2_image.h, did all the setup, but it still isn't working. The image is in the same directory as the cpp file. When I run my program, it runs, but prints error. Here is the function to load the image:
void loadImage()
{
image = IMG_Load("Untitled.png");
if (image == NULL)
std::cout << "error: " << SDL_GetError();
}
The error message from SDL_GetError is Failed loading libpng16-16.dll: The specified module could not be found. I tried passing the full path, but it gives an error and I don't know how to get around that problem since I am a beginner. Thanks.
Edit: After reading through the article linked in the answer to the tagged-duplicate question and making some changes(particularly installing the missing dll file and putting it in the same directory as the main cpp flie), I am getting this error message in a pop-up window: The procedure entry point inflateValidate could not be located in the dynamic link library, and the path to libpng16-16.dll is given after that.

Related

How to fix SFML "failed to load Image" in c++ ? (junk characters) (Resolve)

I have a problem with sfml... everything was working fine but now I can't load any image. Whenever I try, I have the error "Failed to load Image" with a bunch of junk characters...
How can I fix it?
Please check that you are linking correct versions of sfml libs.
If you are buildign in debug mode, make sure to link debug versions of lib files (*-d.lib).

SDL Mix_LoadMUS not loading .mp3

So Apparently i've been trying to load an .mp3 using SDL_mixer. However, this does not work, as opposed to the libsdl wiki: SDL_mixer Mix_LoadMUS
I was hoping for it to work, but when loading and playing the file, the following errors popped in my console app:
Mix_LoadMUS: Unrecognized audio format
Mix_PlayMusic: music parameter was NULL
To my extent, i've been trying to load test.mp3 the following way:
Mix_Music * m_mainMusic;
m_mainMusic = Mix_LoadMUS("test.mp3");
if (m_mainMusic != nullptr)
printf("Loaded the file\n");
else
printf("Mix_LoadMUS: %s\n", Mix_GetError());
if (Mix_PlayMusic(m_mainMusic, -1) == -1)
printf("Mix_PlayMusic: %s\n", Mix_GetError());
I have obviously initialized the SDL subsystem.
With the help of the above explanations I tried to reproduce your issue, and the only thing that caused something similar was the lack of runtime libraries. Make sure that all the necessary libraries are available during runtime (copy them in the folder of your executable or set an environment variable or use static linking.) The runtime libraries distributed with SDL_mixer are the following ones: libmpg123-0, libmodplug-1, libFLAC-8, libogg-0, libopus-0, libopusfile-0, libvorbis-0, libvorbisfile-3 and SDL2_mixer.
These can be acquired here: https://www.libsdl.org/projects/SDL_mixer/

OpenSceneGraph not loading openflight plugin

I have a problem loading an openflight (*.flt) model into Openscenegraph using a simple test app:
#include <osgDB/ReadFile>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
// Setting the message level low so I can read Debug messages
osg::setNotifyLevel(osg::NotifySeverity::DEBUG_FP);
cout << "Opening flt file..." << endl;
osg::ref_ptr<osg::Node> mdl = osgDB::readNodeFile(argv[1]);
if (mdl != NULL) cout << "Opening flt file successful" << endl;
else cout << "Opening flt file failed" << endl;
return 0;
}
This should read the file pyramid.flt, which is in my executable directory by passing the file as argument to the application. However, OSG does not seem to be able to load the required Openflight plugin to indeed read the file. And thus the program returns NULL when trying to load it.
The strange thing is that the debug messages tell me that the required DLL is being used, see below:
Opening flt file...
itr='C:\dev\CgfGen\build32\3dviewer\Debug'
FindFileInPath() : trying C:\dev\CgfGen\build32\3dviewer\Debug\osgPlugins-3.4.1\osgdb_openflightd.dll ...
FindFileInPath() : USING C:\dev\CgfGen\build32\3dviewer\Debug\osgPlugins-3.4.1\osgdb_openflightd.dll
DynamicLibrary::failed loading "osgPlugins-3.4.1/osgdb_openflightd.dll"
Warning: Could not find plugin to read objects from file "pyramid.flt".
Opening flt file failed
I the pyramid.flt is in Openflight version 16.5.
I am running the debug version of my app.
OSG is loading the debug version of osgdb_openflightd.dll
Does anyone have any idea on what the problem is? and how it can be solved?
FindFileInPath() : USING C:\dev\CgfGen\build32\3dviewer\Debug\osgPlugins-3.4.1\osgdb_openflightd.dll
This just means that OSG has discovered a file matching the name of the one it's looking for, but doesn't mean that it is successfully USING it. The next line:
DynamicLibrary::failed loading "osgPlugins-3.4.1/osgdb_openflightd.dll"
Indicates that the plugin failed to load. This could be because of a problem with the plugin's own dependencies. Did you build OSG and the plugins yourself, from scratch?
You can probably use depends.exe to check and see what other DLLs your FLT plugin requires. You could also use something like SysInternals' Process Monitor to see what OSG was trying to load after

OpenCV error when loading Fisher face recognizer in Xcode 8

I've imported opencv and opencv_contrib frameworks in an Xcode project, and in my Objective-C++ file, I load a face classifier and then a Fisher face recognizer:
// set up classifier, recognizer, and webcam
-(void) setupAnalyzer:(NSString *)faceCascadeName :(NSString *)fisherDatasetName
{
// load face classifier
cout << "loading face classifier..." << endl;
String faceCascadeNameString = string([faceCascadeName UTF8String]);
faceCascade.load(faceCascadeNameString);
// load face recognizer
cout << "loading face recognizer..." << endl;
fishface = createFisherFaceRecognizer();
String fisherDatasetNameString = string([fisherDatasetName UTF8String]);
fishface->load(fisherDatasetNameString);
}
When I call this function from Swift, it seems the face classifier loads just fine with an xml file I have in my project. But when I try to load the Fisher face recognizer using another xml file in my project, Xcode shows this error:
OpenCV Error: Unspecified error (File can’t be opened for reading!) in load, file ~/opencv/modules/face/src/facerec.cpp, line 61
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: ~/opencv/modules/face/src/facerec.cpp:61: error: (-2) File can’t be opened for reading! in function load
I've tried rebuilding the OpenCV frameworks in different ways and I keep getting the same error!
First of all, I'm confused why the program is looking to source code that isn't contained in the project (it's looking for facerec.cpp in another directory on my computer). Also, why does the cascade classifier load just fine? This makes me think it's an issue with the way I built the opencv_contrib modules, because the face classifier comes from opencv_contrib. But I tried rebuilding opencv_contrib, and I still get this OpenCV error.
Any help would be greatly appreciated!
[UPDATE]
It is not an issue with building the contrib module. I manually included the module in Xcode, so it's now looking within the project for the facerec.cpp, but it still can't open the xml file for reading.
First of all, I'm confused why the program is looking to source code that isn't contained in the project (it's looking for facerec.cpp in another directory on my computer).
It doesn't search for file. It shows you where error was happen. Since your library was build on your machine and has debug information it can point you source file and line number where error happen.
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: ~/opencv/modules/face/src/facerec.cpp:61: error: (-2) File can’t be opened for reading! in function load
This message means that exception was generated at line 61 in file facerec.cpp. You need to check if your data is available for reading.
Figured it out! This answer helped me realize that I needed to get the app bundle's path to the xml files: OpenCV Cascade Classifier load error iOS

loadFromFile() not loading in sfml

I'm using sfml 2.1 in xcode4. ballSpriteSheet.png is in the project folder. It loads using a full file path. Why won't the file load as written? If not possible as written, can you at least set a relative path?
if(!tBall.loadFromFile("ballSpriteSheet.png"))
std::cout << "ERROR: Could not load ball sprite sheet!" << std::endl;
In output...
Failed to load image "ballSpriteSheet.png". Reason : Unable to open file
ERROR: Could not load ball sprite sheet!
Thanks in advance!
The error reffer to the image that cannot be found. Please check the image to be in the project or to be next to your '.exe' and to be named correctly.