Compare commits

..

1 Commits

Author SHA1 Message Date
verysecrethero e7de7ccf8c Just a reminder to not return at friendly fire because of Boosts 2016-03-03 17:47:07 +01:00
4 changed files with 103 additions and 83 deletions
+1 -2
View File
@@ -2,8 +2,7 @@
#define MiniDump_h__ #define MiniDump_h__
#include <Windows.h> #include <Windows.h>
#include <DbgHelp.h>
long WINAPI Create_Dump_Immediate(LPEXCEPTION_POINTERS pException); void WINAPI Create_Dump(PEXCEPTION_POINTERS pException, BOOL File_Flag, BOOL Show_Flag);
#endif #endif
+80 -71
View File
@@ -1,101 +1,110 @@
/* /*
Inspired by Original Author: Vladimir Sedach. Author: Vladimir Sedach.
Purpose: demo of Call Stack creation by our own means, Purpose: demo of Call Stack creation by our own means,
and with MiniDumpWriteDump() function of DbgHelp.dll. and with MiniDumpWriteDump() function of DbgHelp.dll.
*/ */
#include "MiniDump.h"
#include <string>
#include <iostream> #include <iostream>
#include <ctime> #include <ctime>
#include <comdef.h>
#pragma optimize("y", off) //generate stack frame pointers for all functions - same as /Oy- in the project #include <windows.h>
#pragma warning(disable: 4200) //nonstandard extension used : zero-sized array in struct/union #include <tlhelp32.h>
#pragma warning(disable: 4100) //unreferenced formal parameter //#include "dbghelp.h"
typedef BOOL(WINAPI * MINIDUMP_WRITE_DUMP)( //#define DEBUG_DPRINTF 1 //allow d()
IN HANDLE hProcess, //#include "wfun.h"
IN DWORD ProcessId,
IN HANDLE hFile, #pragma optimize("y", off) //generate stack frame pointers for all functions - same as /Oy- in the project
IN MINIDUMP_TYPE DumpType, #pragma warning(disable: 4200) //nonstandard extension used : zero-sized array in struct/union
IN CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, OPTIONAL #pragma warning(disable: 4100) //unreferenced formal parameter
IN PVOID UserStreamParam, OPTIONAL
IN PVOID CallbackParam OPTIONAL // In case you don't have dbghelp.h.
); #ifndef _DBGHELP_
typedef struct _MINIDUMP_EXCEPTION_INFORMATION {
DWORD ThreadId;
PEXCEPTION_POINTERS ExceptionPointers;
BOOL ClientPointers;
} MINIDUMP_EXCEPTION_INFORMATION, *PMINIDUMP_EXCEPTION_INFORMATION;
typedef enum _MINIDUMP_TYPE {
MiniDumpNormal = 0x00000000,
MiniDumpWithDataSegs = 0x00000001,
} MINIDUMP_TYPE;
typedef BOOL (WINAPI * MINIDUMP_WRITE_DUMP)(
IN HANDLE hProcess,
IN DWORD ProcessId,
IN HANDLE hFile,
IN MINIDUMP_TYPE DumpType,
IN CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, OPTIONAL
IN PVOID UserStreamParam, OPTIONAL
IN PVOID CallbackParam OPTIONAL
);
#else
typedef BOOL (WINAPI * MINIDUMP_WRITE_DUMP)(
IN HANDLE hProcess,
IN DWORD ProcessId,
IN HANDLE hFile,
IN MINIDUMP_TYPE DumpType,
IN CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, OPTIONAL
IN PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, OPTIONAL
IN PMINIDUMP_CALLBACK_INFORMATION CallbackParam OPTIONAL
);
#endif //#ifndef _DBGHELP_
HMODULE hDbgHelp;
MINIDUMP_WRITE_DUMP MiniDumpWriteDump_;
// Tool Help functions.
typedef HANDLE (WINAPI * CREATE_TOOL_HELP32_SNAPSHOT)(DWORD dwFlags, DWORD th32ProcessID);
//************************************************************************************* //*************************************************************************************
long WINAPI Create_Dump_Immediate(LPEXCEPTION_POINTERS pException) void WINAPI Create_Dump(PEXCEPTION_POINTERS pException, BOOL File_Flag, BOOL Show_Flag)
//************************************************************************************* //*************************************************************************************
// Create dump. // Create dump.
// pException can be either GetExceptionInformation() or NULL. // pException can be either GetExceptionInformation() or NULL.
// If File_Flag = TRUE - write dump files (.dmz and .dmp) with the name of the current process.
// If Show_Flag = TRUE - show message with Get_Exception_Info() dump.
{ {
// Try to get MiniDumpWriteDump() address. // Try to get MiniDumpWriteDump() address.
HMODULE hDbgHelp = LoadLibrary("DBGHELP.DLL"); hDbgHelp = LoadLibrary("DBGHELP.DLL");
MINIDUMP_WRITE_DUMP MiniDumpWriteDump_ = (MINIDUMP_WRITE_DUMP)GetProcAddress(hDbgHelp, "MiniDumpWriteDump"); MiniDumpWriteDump_ = (MINIDUMP_WRITE_DUMP)GetProcAddress(hDbgHelp, "MiniDumpWriteDump");
// If MiniDumpWriteDump() of DbgHelp.dll available. // If MiniDumpWriteDump() of DbgHelp.dll available.
if (MiniDumpWriteDump_) { if (MiniDumpWriteDump_)
// Get absolute path of current process: C:/ ... /name.exe {
CHAR Dump_Path[MAX_PATH]; HANDLE hDump_File;
GetModuleFileName(NULL, Dump_Path, sizeof(Dump_Path)); CHAR Dump_Path[MAX_PATH];
std::string path(Dump_Path);
// Get current time in a string. GetModuleFileName(NULL, Dump_Path, sizeof(Dump_Path)); //path of current process
std::time_t t = std::time(NULL); std::time_t t = std::time(NULL);
char tStr[16]; char tStr[16];
std::strftime(tStr, ARRAYSIZE(tStr), " %a %H-%M-%S", std::localtime(&t)); std::strftime(tStr, 32, " %a %H-%M-%S", std::localtime(&t));
std::string time(tStr); std::string time(tStr);
// Remove the .exe from path std::string path(Dump_Path);
path = path.substr(0, path.length() - 4); path = path.substr(0, path.length() - 4);
// Add the current time and .dmp path += time + ".dmp";
path += "dump" + time + ".dmp";
DWORD procId = GetCurrentProcessId(); MINIDUMP_EXCEPTION_INFORMATION M;
DWORD threadId = GetCurrentThreadId(); M.ThreadId = GetCurrentThreadId();
M.ExceptionPointers = pException;
M.ClientPointers = 0;
MINIDUMP_EXCEPTION_INFORMATION M; hDump_File = CreateFile(path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
M.ThreadId = threadId;
M.ExceptionPointers = pException;
M.ClientPointers = TRUE;
HANDLE hDump_File = CreateFile(path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); MiniDumpWriteDump_(GetCurrentProcess(), GetCurrentProcessId(), hDump_File,
HANDLE process = GetCurrentProcess(); MiniDumpNormal, (pException) ? &M : NULL, NULL, NULL);
BOOL result = MiniDumpWriteDump_(process, procId, hDump_File CloseHandle(hDump_File);
, (MINIDUMP_TYPE)(MiniDumpWithDataSegs |
MiniDumpWithHandleData |
MiniDumpScanMemory |
MiniDumpWithUnloadedModules |
MiniDumpWithIndirectlyReferencedMemory |
MiniDumpWithPrivateReadWriteMemory |
MiniDumpWithFullMemoryInfo |
MiniDumpWithThreadInfo |
MiniDumpIgnoreInaccessibleMemory)
, &M, NULL, NULL);
HRESULT error = (HRESULT)GetLastError();
CloseHandle(hDump_File); std::cout << "Memory dumped to: \"" << path.c_str() << "\"";
if (!result) { MessageBox(NULL, ("Application crashed, memory dumped to: " + path).c_str(), "MiniDump", MB_ICONHAND | MB_OK);
_com_error cErr(error);
HRESULT actualErrorCode = error & 0xFFFF;
char hexErrBuf[16];
std::sprintf(hexErrBuf, "0x%x", actualErrorCode);
std::cout << "Bad memory dump at: \"" << path.c_str() << "\"" << std::endl
<< "because MiniDumpWriteDump failed with error #" << actualErrorCode << " (" << hexErrBuf << "): \"" << cErr.ErrorMessage() << "\"" << std::endl;
MessageBox(NULL, "Application crashed, memory dump failed, but file was created.", "MiniDump", MB_ICONHAND | MB_OK);
} else {
std::cout << "Memory dumped to: \"" << path.c_str() << "\"" << std::endl;
MessageBox(NULL, ("Application crashed, memory dumped to: " + path).c_str(), "MiniDump", MB_ICONHAND | MB_OK);
}
} else { } else {
std::cout << "Memory dump failed because MiniDumpWriteDump is not available." << std::endl; MessageBox(NULL, "Application crashed, memory dump failed.", "MiniDump", MB_ICONHAND | MB_OK);
MessageBox(NULL, "Application crashed, could not create a memory dump.", "MiniDump", MB_ICONHAND | MB_OK);
} }
// Basically, terminate the application.
return EXCEPTION_EXECUTE_HANDLER;
} }
@@ -147,8 +147,9 @@ void DefenderWeaponBehaviour::dealDamage(WeaponInfo& wi, glm::vec3 direction, do
} }
// Check for friendly fire // Check for friendly fire
//this needs to not return, for the boosts. in all weaponclasses: assault,defender,sniper
if ((ComponentInfo::EnumType)victim["Team"]["Team"] == (ComponentInfo::EnumType)wi.Player["Team"]["Team"]) { if ((ComponentInfo::EnumType)victim["Team"]["Team"] == (ComponentInfo::EnumType)wi.Player["Team"]["Team"]) {
return; damage = 0;
} }
// Deal damage! // Deal damage!
@@ -181,7 +182,7 @@ Camera DefenderWeaponBehaviour::cameraFromEntity(EntityWrapper camera)
(double)cCamera["FOV"], (double)cCamera["FOV"],
(double)cCamera["NearClip"], (double)cCamera["NearClip"],
(double)cCamera["FarClip"] (double)cCamera["FarClip"]
); );
cam.SetPosition(cTransform["Position"]); cam.SetPosition(cTransform["Position"]);
cam.SetOrientation(glm::quat((const glm::vec3&)cTransform["Orientation"])); cam.SetOrientation(glm::quat((const glm::vec3&)cTransform["Orientation"]));
return cam; return cam;
+15 -4
View File
@@ -1,16 +1,27 @@
#include "Game.h" #include "Game.h"
#include "MiniDump.h" #include "MiniDump.h"
LONG WINAPI CrashHandler(EXCEPTION_POINTERS* pException);
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
SetUnhandledExceptionFilter(Create_Dump_Immediate); ::SetUnhandledExceptionFilter(CrashHandler);
Game game(argc, argv); Game game(argc, argv);
while (game.Running()) { while (game.Running()) {
PerformanceTimer::StartTimer("Game-Tick"); PerformanceTimer::StartTimer("Game-Tick");
game.Tick(); game.Tick();
PerformanceTimer::StopTimer("Game-Tick"); PerformanceTimer::StopTimer("Game-Tick");
} }
return 0; return 0;
}
LONG WINAPI CrashHandler(EXCEPTION_POINTERS* pException)
{
//Take minidump. path should be bin/TacticalZ.dmp
//Then show MessageBox, and exit application.
Create_Dump(pException, 1, 1);
return EXCEPTION_EXECUTE_HANDLER;// EXCEPTION_CONTINUE_SEARCH
} }