SDL IMG_loadTexture and other harddisks - c++

I have recently started working on a small program with SDL2 and c++. In this program I used IMG_LoadTexture() to load a texture however it just would not want to work, the program could not find the image. So I chanced my program to use SDL_loadBMP(), did not work. After hours of endlessly looking for bugs I still could not find anything.
When I started my project I saved it to my D: disk and not on my C: disk. So when I was about to give up on the whole project I copied my exe, image and libraries to my C: disk and Boom it worked.
So I have no idea why this happens. I refer to my image with a relative path but it just doesn't want to work on my D: disk. Is this a bug? or might it have something to do with settings related to my disk? And how can I make it work on my D: disk?
P.S. I am using windows 7
P.S.S. My apologies in advance for any horrible grammar and spelling mistakes.

Is the working directory of you executable the same you assume it is? On windows happened more than one time that working directory was not the path I believed. With certain compiler configurations the working directory is not the same on wich the executable is, you have to change working directory looking at documentation of your IDE.
What frequently happened to me
CURRENT WORKING DIR
D:/projectdir/
EXPECTED WORKING DIR
D:/projectdir/bin/debug/
where files really are:
D:/projectdir/bin/debug/app.exe
D:/projectdir/bin/debug/texture.png
which files app is trying to loading when launched from IDE:
D:/projectdir/app.exe
D:/projectdir/texture.png
You can quickly test wich is current working directory by calling equivalent on windows of
getcwd (answer from here )
#include <WinBase.h>
int main() {
TCHAR pwd[MAX_PATH];
GetCurrentDirectory(MAX_PATH,pwd);
MessageBox(NULL,pwd,pwd,0);
}

Related

System error - "the code cannot proceed because .dll was not found."

I'm getting this error when I try to run my app:
I checked and there is no reason that I can see that it wouldn't be able to find libnlopt-0.dll. Here it is (note GlassModelCalcualator is the DLL that uses libnlopt-0.dll), in the GlassModelCalcualatorDLL folder:
and in the debug folder of GlassModelCalcualatorDLL:
I have a different program that has a console which uses GlassModelCalcualator.dll and that also has this issue. To fix that, I had to put libnlopt-0.dll in the Debug folder of GlassModelCalcualator.
I'm assuming this is not the same problem here since you can clearly see that libnlopt-0.dll is in GlassModelCalcualator's Debug folder.
Any ideas?
Windows will follow a hierarchical order when searching for dll's.
You could place your dll in the same directory as the exe or even in the Windows system folders (only if you're absolutely sure you want to keep this dll forever as there's no cleanup)
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v=vs.85).aspx

Trouble getting a Qt Reference Document program to work(Minehunt)... its just blank when run... no errors though?

http://docs.huihoo.com/qt/4.7/demos-declarative-minehunt.html
When I build and run... I just get a blank white rectangle... game is MineHunt.
The source code is in the URL. I created files and copied and pasted into Qt Creator 4.7.
Running in Linux.
No need to downvote. Deploying qml apps does not seem to be easy for beginners. jdl, I don't know if I can help you. Currently I am only on Linux. But what I did:
I copied the whole folder minehunt in my destination folder (/tmp/mine). When I ran qmake I got:
WARNING: Include file
/tmp/mine/helper/qmlapplicationviewer/qmlapplicationviewer.pri not
found
So I also copied the examples/declarative/helper folder into /tmp/mine.
Looked like this:
/tmp
/mine
/minehunt
/helper
Then I changed into minhunt, did 'qmake' and 'make'. A few seconds later I had a working minehunt binary in /tmp/mine/minehunt/.
I'll try tomorrow the Windows build.
Edit: Ok, tried now under Windows 7. Qt4.
QtCreator opened.
Project ...qt\demos\declarative\minehunt\minehunt.pro
loaded. Normally in release mode compiled. No problem. A file minehunt.exe was created in ....qt\demos\declarative\minehunt\release. Started: White screen. Exactly as you described it. In ...qt\demos\declarative\minehunt I found a folder 'qml'. I moved this folder and the minehunt.exe into another folder (myMineFolder). Simulating a simple deployment this way. Clicked on minehunt.exe -> worked like a charm.
So my folder layout:
myMineFolder
qml
minehunt.exe
But of course, I have set my PATH variable correctly to my Qt installation.

WxWidgets - Unable to load images

I recently started working with WxWidgets (2.9.4) and was working through a tutorial I found, but it seems that I'm unable to load any images. I've already properly used the handler (for PNG) and the problem happens at run-time. Below is an image of the popup that is displayed when attempting to run the program.
Here is the code:
wxPNGHandler *handler = new wxPNGHandler;
wxImage::AddHandler(handler);
wxBitmap exit;
exit.LoadFile(wxT("exit.png"), wxBITMAP_TYPE_PNG);
wxToolBar *toolbar = CreateToolBar();
toolbar->AddTool(wxID_EXIT, exit, wxT("Exit"));
toolbar->Realize();
Connect(wxID_EXIT, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(mainWindow::exitProg));
Any help is appreciated.
EDIT: I forgot to mention that when I click Cancel, this happens:
I placed the exit.png file in the build directory (/Debug or /Release) as well as the source code directory, but it still has yet to see it.
What is your working directory?
If you are using visual studio and running using the interface ( F5 or ctrl-F5 or the little run button in the toolbar ) then your working directory is the folder containing the project file. So try copying your image file there.
Or open a command window, cd to one of your build directories, and run your app from the command line.
In general, to avoid this sort of problem, I alter the project properties so that the executable is NOT stored in one of the build folders, but in a new folder ( which I usually call 'bin' - my unix roots are showing! ) and also alter the debugging properties so that the working directory is the bin folder.
There are a couple of advantages to this technique:
Both the release and trhe debug version use the same folder, so you only need one copy of any extra file, like your image file.
It is easy to see the executable and extra files in the working directory without being distracted by all the .obj files that end up in the build folders
IMHO this is well worth the little extra trouble in maintaining non default project properties.
First of all, to avoid problems deep inside wxToolBar, always check the return code of LoadFile() or, alternatively, use wxBitmap::IsOk() to check that the bitmap was successfully loaded.
Second, while adding the handler explicitly as you did is perfectly fine, I'd recommend to just call wxInitAllImageHandlers() as it's simpler and has no real drawbacks unless you are looking to create the smallest program possible.
Finally, to address your real problem, the file clearly doesn't exist at the path you're loading it from. You can, of course, solve this by being careful not to change your working directly (or restore it after changing it) in your program and by placing the file in the correct place. But this is, as you discovered, error-prone, so a better idea is to always use full paths to your resources. To construct them, you will find wxStandardPaths useful, in particular its GetResourcesDir() method.

Why is SDL not loading my images when main application is accessed via shortcut?

I have recently created a program using C++ and the SDL library. Originally, all the images and DLLs were in the same folder as the main application. I wanted to make the main application easier to find, so I instead moved all the images into their own folder and modified my source code to find them in the correct folder. So far, so good. The main application still remains in the same folder as the DLLs.
I created a shortcut to the main application and put that it's own folder. I changed the target to %windir%\system32\cmd.exe /q/c start "" ""%SystemRoot%\explorer.exe %UserProfile%\Desktop\Cupcake Corner Build 2.0 (exe test)\dependecies\Cupcake Corner.exe" in an attempt to make a universal shortcut, so that the shortcut would work for any user I send the files to.
After all said and done, I've ran into a problem. If I open the main application itself, it will load the images and work perfectly. If I try to the main application via its shortcut, the window will open correctly and display the correct title, although none of the images will load. I tried moving some files around to see if the shortcut would see them if I put the resource folder elsewhere, but so far no luck.
images here -> C:\Users\Admin\Desktop\Cupcake Corner Build 2.0\dependecies\resources
main app/dlls here -> C:\Users\Admin\Desktop\Cupcake Corner Build 2.0\dependecies\
shortcut here -> C:\Users\Admin\Desktop\Cupcake Corner Build 2.0\
I am using Microsoft Visual Studio Express 2010. I think it has something to do with the way I have my project directory set in project options, but I'm honestly baffled at this point. Can anyone point me in the right direction?
Generally, when dealing with files in an application (that the application knows internally, at least), you will want to have absolute paths.
The best way to solve this is by having a (set of) function(s) that add the absolute path (found by GetModuleFilename(0, ...) or from some configuration for example in the registry)
std::string myfiles_root_path = FindMyFilesRootPath();
std::string MakeFullPath(const std::string &filename)
{
return myfiles_root_path + filename;
}
The function FindMyFilesRootPath() uses one of the methods above to find the appropriate path, and filename is the name of a file local to your application.

c++ boost library cannot open file

I tried to work with the boost library to read/write configuration files but I just don't get it.
I even can't run the example code from boost.org (5 Minute Tutorial)
http://www.boost.org/doc/libs/1_49_0/libs/property_tree/examples/debug_settings.cpp
I've downloaded the boost_1_49_0.zip package and unzipped it to my c++ program folder. The code compiles (TheIDE - U++) but it always says "Error: debug_settings.xml: cannot open file" which basically means that the program works, but runs into the exception.
I didn't change the code, I just copy and pasted it to get a working example which I could try to understand then. But I don't even get this one to work. (Since it's exactly the same as in the link, I don't paste the code here... unless you think it's better.)
Please help me... or point to a different way to store variables in a file with some kind of structure (I wan't to learn a way that works for windows and linux, because some of my apps are cross-platform.)
Thanks.
EDIT: debug_settings.xml is in the same folder as the .cpp file
EDIT2: Working now, the debug_settings.xml is now in the folder where the executable is stored. (in my case, U++/TheIDE it's C:\upp\out\MyApps\MINGW.Debug.Debug_Full.Sse2 for debugging)
The configuration file would need to be in the working directory of the executable when it's running.