Browse Source

Replace plasmalog with a better debug log

Plasmalog.txt is now plasmadbg.log. This allows us to view the log inside
the game, flush to the debugger output window, and have the logfile. The
plan is to redirect key leak reports to this log in a future commit.
Adam Johnson 12 years ago
parent
commit
d2815f35bf
  1. 111
      Sources/Plasma/Apps/plClient/winmain.cpp
  2. 14
      Sources/Plasma/CoreLib/hsStream.cpp

111
Sources/Plasma/Apps/plClient/winmain.cpp

@ -305,11 +305,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
bool active = (LOWORD(wParam) == WA_ACTIVE || LOWORD(wParam) == WA_CLICKACTIVE); bool active = (LOWORD(wParam) == WA_ACTIVE || LOWORD(wParam) == WA_CLICKACTIVE);
bool minimized = (HIWORD(wParam) != 0); bool minimized = (HIWORD(wParam) != 0);
DebugMsgF("Got WM_ACTIVATE, active=%s, minimized=%s, clicked=%s",
active ? "true" : "false",
minimized ? "true" : "false",
(LOWORD(wParam) == WA_CLICKACTIVE) ? "true" : "false");
if (gClient && !minimized && !gClient->GetDone()) if (gClient && !minimized && !gClient->GetDone())
{ {
gClient->WindowActivate(active); gClient->WindowActivate(active);
@ -324,7 +319,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
// Let go of the mouse if the window is being moved. // Let go of the mouse if the window is being moved.
case WM_ENTERSIZEMOVE: case WM_ENTERSIZEMOVE:
DebugMsgF("Got WM_ENTERSIZEMOVE%s", gClient ? "" : ", no client, ignoring");
gDragging = true; gDragging = true;
if( gClient ) if( gClient )
gClient->WindowActivate(false); gClient->WindowActivate(false);
@ -332,7 +326,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
// Redo the mouse capture if the window gets moved // Redo the mouse capture if the window gets moved
case WM_EXITSIZEMOVE: case WM_EXITSIZEMOVE:
DebugMsgF("Got WM_EXITSIZEMOVE%s", gClient ? "" : ", no client, ignoring");
gDragging = false; gDragging = false;
if( gClient ) if( gClient )
gClient->WindowActivate(true); gClient->WindowActivate(true);
@ -342,12 +335,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
// and his cool program that bumps windows out from under the taskbar) // and his cool program that bumps windows out from under the taskbar)
case WM_MOVE: case WM_MOVE:
if (!gDragging && gClient && gClient->GetInputManager()) if (!gDragging && gClient && gClient->GetInputManager())
{
gClient->GetInputManager()->Activate(true); gClient->GetInputManager()->Activate(true);
DebugMsgF("Got WM_MOVE");
}
else
DebugMsgF("Got WM_MOVE, but ignoring");
break; break;
/// Resize the window /// Resize the window
@ -358,7 +346,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
// size, not when the window is minimized or restored) // size, not when the window is minimized or restored)
case WM_SIZING: case WM_SIZING:
{ {
DebugMsgF("Got WM_SIZING");
RECT r; RECT r;
::GetClientRect(hWnd, &r); ::GetClientRect(hWnd, &r);
gClient->GetPipeline()->Resize(r.right - r.left, r.bottom - r.top); gClient->GetPipeline()->Resize(r.right - r.left, r.bottom - r.top);
@ -369,14 +356,12 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
// Let go of the mouse if the window is being minimized // Let go of the mouse if the window is being minimized
if (wParam == SIZE_MINIMIZED) if (wParam == SIZE_MINIMIZED)
{ {
DebugMsgF("Got WM_SIZE, SIZE_MINIMIZED%s", gClient ? "" : ", but no client, ignoring");
if (gClient) if (gClient)
gClient->WindowActivate(false); gClient->WindowActivate(false);
} }
// Redo the mouse capture if the window gets restored // Redo the mouse capture if the window gets restored
else if (wParam == SIZE_RESTORED) else if (wParam == SIZE_RESTORED)
{ {
DebugMsgF("Got WM_SIZE, SIZE_RESTORED%s", gClient ? "" : ", but no client, ignoring");
if (gClient) if (gClient)
gClient->WindowActivate(true); gClient->WindowActivate(true);
} }
@ -653,32 +638,40 @@ BOOL WinInit(HINSTANCE hInst, int nCmdShow)
// //
// For error logging // For error logging
// //
static FILE* gDebugFile=NULL; static plStatusLog* s_DebugLog = nullptr;
void DebugMessageProc(const char* msg) static void _DebugMessageProc(const char* msg)
{ {
OutputDebugString(msg); #if defined(HS_DEBUGGING) || !defined(PLASMA_EXTERNAL_RELEASE)
OutputDebugString("\n"); s_DebugLog->AddLine(msg, plStatusLog::kRed);
if (gDebugFile != NULL) #endif // defined(HS_DEBUGGING) || !defined(PLASMA_EXTERNAL_RELEASE)
{
fprintf(gDebugFile, "%s\n", msg);
fflush(gDebugFile);
}
} }
void DebugMsgF(const char* format, ...) static void _StatusMessageProc(const char* msg)
{ {
#ifndef PLASMA_EXTERNAL_RELEASE #if defined(HS_DEBUGGING) || !defined(PLASMA_EXTERNAL_RELEASE)
s_DebugLog->AddLine(msg);
#endif // defined(HS_DEBUGGING) || !defined(PLASMA_EXTERNAL_RELEASE)
}
static void DebugMsgF(const char* format, ...)
{
#if defined(HS_DEBUGGING) || !defined(PLASMA_EXTERNAL_RELEASE)
va_list args; va_list args;
va_start(args, format); va_start(args, format);
s_DebugLog->AddLineV(plStatusLog::kYellow, format, args);
char buf[256];
int numWritten = _vsnprintf(buf, sizeof(buf), format, args);
hsAssert(numWritten > 0, "Buffer too small");
va_end(args); va_end(args);
#endif // defined(HS_DEBUGGING) || !defined(PLASMA_EXTERNAL_RELEASE)
}
DebugMessageProc(buf); static void DebugInit()
#endif {
#if defined(HS_DEBUGGING) || !defined(PLASMA_EXTERNAL_RELEASE)
plStatusLogMgr& mgr = plStatusLogMgr::GetInstance();
s_DebugLog = mgr.CreateStatusLog(30, "plasmadbg.log", plStatusLog::kFilledBackground |
plStatusLog::kDeleteForMe | plStatusLog::kAlignToTop | plStatusLog::kTimestamp);
hsSetDebugMessageProc(_DebugMessageProc);
hsSetStatusMessageProc(_StatusMessageProc);
#endif // defined(HS_DEBUGGING) || !defined(PLASMA_EXTERNAL_RELEASE)
} }
static void AuthFailedStrings (ENetError authError, static void AuthFailedStrings (ENetError authError,
@ -1203,6 +1196,7 @@ LONG WINAPI plCustomUnhandledExceptionFilter( struct _EXCEPTION_POINTERS *Except
#include "pfConsoleCore/pfConsoleEngine.h" #include "pfConsoleCore/pfConsoleEngine.h"
PF_CONSOLE_LINK_ALL() PF_CONSOLE_LINK_ALL()
#include "plResMgr/plVersion.h"
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow) int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
{ {
PF_CONSOLE_INIT_ALL() PF_CONSOLE_INIT_ALL()
@ -1398,22 +1392,8 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nC
// //
// Set up to log errors by using hsDebugMessage // Set up to log errors by using hsDebugMessage
// //
gDebugFile = NULL; DebugInit();
if ( !plStatusLog::fLoggingOff ) DebugMsgF("Plasma 2.0.%i.%i - %s", PLASMA2_MAJOR_VERSION, PLASMA2_MINOR_VERSION, plProduct::ProductString().c_str());
{
wchar_t fileAndPath[MAX_PATH];
PathGetLogDirectory(fileAndPath, arrsize(fileAndPath));
PathAddFilename(fileAndPath, fileAndPath, L"plasmalog.txt", arrsize(fileAndPath));
gDebugFile = _wfopen(fileAndPath, L"wt");
hsAssert(gDebugFile != NULL, "Error creating debug file plasmalog.txt");
hsSetDebugMessageProc(DebugMessageProc);
if (gDebugFile != NULL)
{
fputs(plProduct::ProductString().c_str(), gDebugFile);
fputs("\n", gDebugFile);
fflush(gDebugFile);
}
}
for (;;) { for (;;) {
// Create Window // Create Window
@ -1485,32 +1465,17 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nC
break; break;
} }
#ifndef _DEBUG //
try // Cleanup
{ //
#endif if (gClient)
//
// Cleanup
//
if (gClient)
{
gClient->Shutdown(); // shuts down PhysX for us
gClient = nil;
}
hsAssert(hsgResMgr::ResMgr()->RefCnt()==1, "resMgr has too many refs, expect mem leaks");
hsgResMgr::Shutdown(); // deletes fResMgr
DeInitNetClientComm();
#ifndef _DEBUG
} catch (...)
{ {
// just catch all the crashes on exit... just to keep GameTap from complaining gClient->Shutdown(); // shuts down PhysX for us
if (gDebugFile) gClient = nil;
fprintf(gDebugFile, "Crashed on shutdown.\n");
} }
#endif hsAssert(hsgResMgr::ResMgr()->RefCnt()==1, "resMgr has too many refs, expect mem leaks");
hsgResMgr::Shutdown(); // deletes fResMgr
if (gDebugFile) DeInitNetClientComm();
fclose(gDebugFile);
// Uninstall our unhandled exception filter, if we installed one // Uninstall our unhandled exception filter, if we installed one
#ifndef HS_DEBUGGING #ifndef HS_DEBUGGING

14
Sources/Plasma/CoreLib/hsStream.cpp

@ -714,17 +714,13 @@ uint32_t hsUNIXStream::Read(uint32_t bytes, void* buffer)
{ {
if (!fRef || !bytes) if (!fRef || !bytes)
return 0; return 0;
int numItems = ::fread(buffer, 1 /*size*/, bytes /*count*/, fRef); size_t numItems = ::fread(buffer, 1 /*size*/, bytes /*count*/, fRef);
fBytesRead += numItems; fBytesRead += numItems;
fPosition += numItems; fPosition += numItems;
if ((unsigned)numItems < bytes) { if (numItems < bytes)
if (feof(fRef)) { {
// EOF ocurred if (!feof(fRef))
char str[128]; {
sprintf(str, "Hit EOF on UNIX Read, only read %d out of requested %d bytes\n", numItems, bytes);
hsDebugMessage(str, 0);
}
else {
hsDebugMessage("Error on UNIX Read", ferror(fRef)); hsDebugMessage("Error on UNIX Read", ferror(fRef));
} }
} }

Loading…
Cancel
Save