我将minGW文件夹中的“ true” gdb.exe定义为“设置”>“调试器设置”>“可执行路径”,从而解决了调试问题。
我正在用C和Glut编写类似于2D粒子模拟器的作业,我有4个标题,2个源。运行代码时,我看到
Process returned -1073741819 (0xC0000005)
,我尝试使用CodeBlocks进行调试,以找出错误的地方。
这是调试日志:
Active debugger config: GDB/CDB debugger:Default
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: C:\Users\emiry\Desktop\CMPE 252\Workspace\2DParticleSimulator\
Adding source dir: C:\Users\emiry\Desktop\CMPE 252\Workspace\2DParticleSimulator\
Adding file: C:\Users\emiry\Desktop\CMPE 252\Workspace\2DParticleSimulator\bin\Debug\2DParticleSimulator.exe
Changing directory to: C:/PROGRA~2/CODEBL~1/MinGW/bin
Set variable: PATH=.;C:\Program Files (x86)\CodeBlocks\MinGW\lib;C:\Program Files (x86)\CodeBlocks\MinGW\bin;C:\Program Files (x86)\CodeBlocks\MinGW;C:\oraclexe\app\oracle\product\11.2.0\server\bin;C:\ProgramData\Oracle\Java\javapath;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\Common Files\LENOVO\easyplussdk\bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Intel\WiFi\bin;C:\Program Files\Common Files\Intel\WirelessCommon;C:\Windows\System32\OpenSSH;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Go\bin;C:\Program Files\Git\cmd;C:\Users\emiry\AppData\Local\Programs\Python\Python35\Scripts;C:\Users\emiry\AppData\Local\Programs\Python\Python35;C:\Users\emiry\AppData\Local\Microsoft\WindowsApps;%JAVA_HOME%\bin;%SPARK_HOME%\bin;\;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.3.4\bin;C:\Users\emiry\go\bin
[debug]Command-line: C:\Users\emiry\Desktop\CMPE 252\Workspace\2DParticleSimulator\bin\Debug\2DParticleSimulator.exe -nx -fullname -quiet -args C:/Users/emiry/Desktop/CMPE25~1/WORKSP~1/2DPART~1/bin/Debug/2DPART~1.EXE
[debug]Working dir : C:\PROGRA~2\CODEBL~1\MinGW\bin
Starting debugger: C:\Users\emiry\Desktop\CMPE 252\Workspace\2DParticleSimulator\bin\Debug\2DParticleSimulator.exe -nx -fullname -quiet -args C:/Users/emiry/Desktop/CMPE25~1/WORKSP~1/2DPART~1/bin/Debug/2DPART~1.EXE
done
[debug]> set prompt >>>>>>cb_gdb:
Setting breakpoints
Debugger finished with status 1
这是我一生中第一次调试的尝试。所以,请给我清楚的答案,我可能听不懂。
main.c代码
#include <windows.h>
#include "GL_Related.h"
#include "simulation.h"
simulation* simb;
float timeElapsed = 0;
int showGrid = 1;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
Application application;
GL_Window window;
Keys keys;
BOOL isMessagePumpActive;
MSG msg;
DWORD tickCount;
application.className = "OpenGL";
application.hInstance = hInstance;
ZeroMemory(&window, sizeof(GL_Window));
window.keys = &keys;
window.init.application = &application;
window.init.title = "Simulation Window";
window.init.width = 800;
window.init.height = 600;
window.init.bitsPerPixel = 16;
window.init.isFullScreen = FALSE;
ZeroMemory(&keys, sizeof(Keys));
if (RegisterWindowClass(&application) == FALSE)
{
MessageBox(HWND_DESKTOP, "Error Registering Window Class!", "Error", MB_OK | MB_ICONEXCLAMATION);
return -1;
}
g_isProgramLooping = TRUE;
g_createFullScreen = window.init.isFullScreen;
while (g_isProgramLooping)
{
window.init.isFullScreen = g_createFullScreen;
if (CreateWindowGL(&window) == TRUE)
{
if (Initialize(&window, &keys) == FALSE)
{
TerminateApplication(&window);
}
else
{
isMessagePumpActive = TRUE;
while (isMessagePumpActive == TRUE)
{
if (PeekMessage(&msg, window.hWnd, 0, 0, PM_REMOVE) != 0)
{
if (msg.message != WM_QUIT)
{
DispatchMessage(&msg);
}
else
{
isMessagePumpActive = FALSE;
}
}
else
{
if (window.isVisible == FALSE)
{
WaitMessage();
}
else
{
tickCount = GetTickCount();
Update(tickCount - window.lastTickCount);
window.lastTickCount = tickCount;
Draw();
SwapBuffers(window.hDC);
}
}
}
}
DestroyWindowGL(&window);
}
else
{
MessageBox(HWND_DESKTOP, "Error Creating OpenGL Window", "Error", MB_OK | MB_ICONEXCLAMATION);
g_isProgramLooping = FALSE;
}
}
UnregisterClass(application.className, application.hInstance);
return 0;
}
void Update(DWORD ms)
{
if (g_keys->keyDown[VK_ESCAPE] == TRUE)
TerminateApplication(g_window);
if (g_keys->keyDown['G'] == TRUE)
if (showGrid == 1)
showGrid = 0;
else
showGrid = 1;
float sec = ms / 1000.0f;
timeElapsed += sec;
simulate(simb);
}
void Draw(void)
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0, 0, 40, 0, 0, 0, 0, 1, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
vector halfWorld;
halfWorld.x = simb->world->x *0.5f;
halfWorld.y = simb->world->y *0.5f;
if (showGrid == 1)
{
glColor3ub(0, 0, 255);
glLineWidth(1);
glBegin(GL_LINES);
for (float x = -halfWorld.x; x <= halfWorld.x; x += 1.0f) // x += 1.0f Stands For 1 Meter Of Space In This Example
{
glVertex3f(x, halfWorld.x, 0);
glVertex3f(x, -halfWorld.x, 0);
}
for (float y = -halfWorld.y; y <= halfWorld.y; y += 1.0f) // y += 1.0f Stands For 1 Meter Of Space In This Example
{
glVertex3f(halfWorld.y, y, 0);
glVertex3f(-halfWorld.y, y, 0);
}
glEnd();
}
glLineWidth(3);
glColor3ub(0, 255, 255);
glBegin(GL_LINES);
glVertex3f(-10, -10, 0);
glVertex3f(10, -10, 0);
glVertex3f(10, -10, 0);
glVertex3f(10, 10, 0);
glVertex3f(10, 10, 0);
glVertex3f(-10, 10, 0);
glVertex3f(-10, 10, 0);
glVertex3f(-10, -10, 0);
glEnd();
for (int a = 0; a < simb->nrOfParticles; a++)
{
vector pos = simb->particleList[a].position;
vector color = simb->particleList[a].color;
glColor3ub((int)color.x, (int)color.y, 0);
glPointSize(6);
glBegin(GL_POINTS);
glVertex3f(pos.x, pos.y, 0);
glEnd();
}
glColor3ub(255, 255, 255);
glPrint(-5.0f, -13, 0, "Time elapsed (seconds): %.2f", timeElapsed);
glPrint(-5.0f, -12, 0, "G:Grid on/off");
glPrint(0.0f, 14, 0, "Simple Gravity System");
glPrint(0.0f, 13, 0, "System Kinetic Energy: %.2f", simb->kineticalenergy);
glPrint(0.0f, 12, 0, "System Potential Energy: %.2f", simb->potentialenergy);
glPrint(0.0f, 11, 0, "System Total Energy: %.2f", (simb->kineticalenergy+simb->potentialenergy));
glFlush();
}