I have a program I've been working on for a number of weeks, and I made some big changes over the past few days and I now can't figure out why the program doesn't work outside of the VC++2010 environment.
The program runs flawlessly when I open up the project, select Release or Debug from the Solution Configurations dropdown, and hit F5. But when I grab the executable from the Release/Debug folder, drop it in a location where it can access the assets I am using, and then run it, it loads for a few seconds and then shows this lovely error "Project.exe has stopped working - Windows is checking for a solution for the problem..." Of course, like always, Windows can't find a solution to the problem.
Quick disclaimer before you read through all this code: While the error has been caused by a change in code, it is doubtful as to which change caused it because I have changed a few things at once - which I know is stupid, but it happened. I've posted code from the most likely source of the error. Scroll to "My second idea:" if you trust in my coding habits.
The biggest recent change I have made involves my input handler, and integrating keybinds via function pointers (with which I have no experience whatsoever). I defined an array of function pointers in a RawInput
class like so:
typedef void (Application::*AppFunc)(void);
typedef void (Application::*AppFuncDelta)(int delta);
AppFunc onKeyPress[256];
AppFunc onKeyRelease[256];
AppFunc onMouseButtonPress[5];
AppFunc onMouseButtonRelease[5];
AppFuncDelta onMouseMove[3];
I have alerted the RawInput
class to the Application
class by declaring a prototype directly above its own class definition like so:
class Application;
and I fill these arrays like so in Application::Initialize()
(I have many keys defined, so here is an excerpt):
m_RawInput->onMouseMove[0] = &Application::mouseMoveX;
m_RawInput->onMouseMove[1] = &Application::mouseMoveY;
where Application::mouseMoveX
and Application::mouseMoveY
function that take an int
argument and do not return a value.
These functions are called inside of RawInput::Interpret(LPARAM lParam)
like so:
if (raw->data.keyboard.Flags & RI_KEY_BREAK) //key released
{
if (onKeyRelease[raw->data.keyboard.VKey] && g_app) (g_app->*onKeyRelease[raw->data.keyboard.VKey])();
return;
}
else //key pressed down
{
if (onKeyPress[raw->data.keyboard.VKey] && g_app) (g_app->*onKeyPress[raw->data.keyboard.VKey])();
return;
}
g_app
is defined in input.cpp
as extern Application *g_app
. I've used g_app
since the program's conception, and it is definitely not a problem.
The first problem I had with this update lay in a null function pointer, but now I run a check the validity of the specified function and the validity of g_app
before calling any function. And at any rate, this error would occur inside as well as outside of the VC++ environment and I suspect it is not the problem.
I searched around for a while prior to asking on my own and found this nearly identical question also on Stack Overflow. Sadly for me, it remains unanswered.
I also discovered this tool(called dependency walker), which goes through all dependencies of an executable and lets you know if some of them are not found. It could not find (and I could not find a definitive version of) these DLLs:
API-MS-WIN-APPMODEL-RUNTIME-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-ERROR-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-ROBUFFER-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-STRING-L1-1-0.DLL
API-MS-WIN-SHCORE-SCALING-L1-1-1.DLL
DCOMP.DLL
GPSVC.DLL
IESHIMS.DLL
One of my two ideas is that RawInput
can't call a function that it doesn't know about - and it doesn't know about any of the functions in Application
. But my current #include
hierarchy makes it very difficult for RawInput
to know about these functions.
My second idea:
There are only 3 things (according to Vivian De Smedt) that change when a program is run inside or outside of an IDE:
1.) The arguments that are passed to the program. //perhaps
2.) The working directory of the application. //has not changed
3.) The environment variables if you changed them after you started Visual Studio (or after you started the launcher if you use such launcher: e.g.: Explorer++) //I suspect this to be the problem. Ideas?
I'm thoroughly lost on this issue, and I've spent a significant amount of time composing this question. Any suggestions are greatly appreciated. I'll be around for 15 minutes, so please request clarification if I lost you anywhere :)