B
benderbendingrodriguez2
Guest
I've created a simple logging mechanism that can write strings to a log file. Everything worked fine until I added the function fclose() to the engine class deconstructor to close the log file.
// Constructor (load)
Engine::Engine(int param_debug)
{
// Set Debug Mode
this->debug = param_debug;
errno_t err;
// Load Log File if Debug Mode is set to DEBUG_MODE_BOTH or DEBUG_MODE_FILE
if (this->debug == DEBUG_MODE_BOTH || this->debug == DEBUG_MODE_FILE)
{
if ((err = fopen_s(&this->log, "log.txt", "w")) != 0)
{
// Failure to load file.
this->log_status = false;
this->print("[_] Failed to load Log File");
}
else
{
// Load success.
this->log_status = true;
this->print("[X] Log File Loaded");
}
}
// Success
this->print("[X] Engine Started (Debug Mode)");
return;
}
// Destructor
Engine::~Engine()
{
// Close Log File
if (this->debug == DEBUG_MODE_FILE || this->debug == DEBUG_MODE_BOTH) fclose(this->log);
// Finnished Cleaning Engine
this->print("[X] Engine Destructor Success\n");
return;
}
The error only occurs when fclose is called. If I comment out fclose everything runs fine. The log output is written to the file successfully either way.
Visual C++ Debug Output
Debug Assertion Failed!
Program: ...Documents\Visual Studio 2015\Projects\engine\Debug\engine.exe
File: minkernel\crts\ucrt\src\appcrt\lowio\isatty.cpp
Line: 17
Expression: (fh >= 0 && (unsigned)fh < (unsigned)_nhandle)
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
'engine.exe' (Win32): Loaded 'C:\Windows\SysWOW64\user32.dll'. Cannot find or open the PDB file.
'engine.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32.dll'. Cannot find or open the PDB file.
'engine.exe' (Win32): Loaded 'C:\Windows\SysWOW64\imm32.dll'. Cannot find or open the PDB file.
'engine.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msctf.dll'. Cannot find or open the PDB file.
'engine.exe' (Win32): Loaded 'C:\Windows\SysWOW64\uxtheme.dll'. Cannot find or open the PDB file.
'engine.exe' (Win32): Loaded 'C:\Windows\SysWOW64\combase.dll'. Cannot find or open the PDB file.
'engine.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dwmapi.dll'. Cannot find or open the PDB file.
'engine.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ole32.dll'. Cannot find or open the PDB file.
The program '[5932] engine.exe' has exited with code 3 (0x3).
Also, when commenting out the fclose call, debug output displays no errors other than a list of
Cannot find or open the PDB file.
and ends successfully with...
The program '[9048] engine.exe' has exited with code 0 (0x0).
Continue reading...