用户回调期间遇到未处理的异常

时间:2018-06-02 17:03:17

标签: c++ winapi

您好我正在关注手工制作的英雄游戏,我收到此错误:&#34; win32_handmade.exe中0x013B56B2处的未处理异常:0xC000041D:在用户回调期间遇到未处理的异常。&#34; < / p>

我不确定导致这种情况的原因是因为我有完全相同的代码,当我构建.bat时,我没有错误。

Visual Studio说错误发生在第62行,这是第二个内部空白处于的位置,但无论有什么错误,都会发生错误。

#include <windows.h>
#include <stdint.h>

#define internal static 
#define local_persist static 
#define global_variable static

typedef int8_t int8;
typedef int16_t int16;
typedef int32_t int32;
typedef int64_t int64;

typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef uint64_t uint64;

// TODO(casey): This is a global for now.
global_variable bool Running;

global_variable BITMAPINFO BitmapInfo;
global_variable void *BitmapMemory;
global_variable int BitmapWidth;
global_variable int BitmapHeight;
global_variable int BytesPerPixel = 4;

internal void
RenderWeirdGradient(int BlueOffset, int GreenOffset)
{
int Width = BitmapWidth;
int Height = BitmapHeight;

int Pitch = Width * BytesPerPixel;
uint8 *Row = (uint8 *)BitmapMemory;
for (int Y = 0;
    Y < BitmapHeight;
    ++Y)
{
    uint32 *Pixel = (uint32 *)Row;
    for (int X = 0;
        X < BitmapWidth;
        ++X)
    {
        uint8 Blue = (X + BlueOffset);
        uint8 Green = (Y + GreenOffset);

        *Pixel++ = ((Green << 8) | Blue);
    }

    Row += Pitch;
}
 }

 internal void
 Win32ResizeDIBSection(int Width, int Height)
 {
// TODO(casey): Bulletproof this.
// Maybe don't free first, free after, then free first if that fails.

if (BitmapMemory)
{
    VirtualFree(BitmapMemory, 0, MEM_RELEASE);
}

BitmapWidth = Width;
BitmapHeight = Height;

BitmapInfo.bmiHeader.biSize = sizeof(BitmapInfo.bmiHeader);
BitmapInfo.bmiHeader.biWidth = BitmapWidth;
BitmapInfo.bmiHeader.biHeight = -BitmapHeight;
BitmapInfo.bmiHeader.biPlanes = 1;
BitmapInfo.bmiHeader.biBitCount = 32;
BitmapInfo.bmiHeader.biCompression = BI_RGB;

// NOTE(casey): Thank you to Chris Hecker of Spy Party fame
// for clarifying the deal with StretchDIBits and BitBlt!
// No more DC for us.
int BitmapMemorySize = (BitmapWidth*BitmapHeight)*BytesPerPixel;
BitmapMemory = VirtualAlloc(0, BitmapMemorySize, MEM_COMMIT, 
 PAGE_READWRITE);

// TODO(casey): Probably clear this to black
 }

 internal void
 Win32UpdateWindow(HDC DeviceContext, RECT *ClientRect, int X, int Y, int 
 Width, int Height)
 {
int WindowWidth = ClientRect->right - ClientRect->left;
int WindowHeight = ClientRect->bottom - ClientRect->top;
StretchDIBits(DeviceContext,
    /*
    X, Y, Width, Height,
    X, Y, Width, Height,
    */
    0, 0, BitmapWidth, BitmapHeight,
    0, 0, WindowWidth, WindowHeight,
    BitmapMemory,
    &BitmapInfo,
    DIB_RGB_COLORS, SRCCOPY);

}

 LRESULT CALLBACK
 Win32MainWindowCallback(HWND Window,
UINT Message,
WPARAM WParam,
LPARAM LParam)
{
LRESULT Result = 0;

switch (Message)
{
case WM_SIZE:
{
    RECT ClientRect;
    GetClientRect(Window, &ClientRect);
    int Width = ClientRect.right - ClientRect.left;
    int Height = ClientRect.bottom - ClientRect.top;
    Win32ResizeDIBSection(Width, Height);
} break;

case WM_CLOSE:
{
    // TODO(casey): Handle this with a message to the user?
    Running = false;
} break;

case WM_ACTIVATEAPP:
{
    OutputDebugStringA("WM_ACTIVATEAPP\n");
} break;

case WM_DESTROY:
{
    // TODO(casey): Handle this as an error - recreate window?
    Running = false;
} break;

case WM_PAINT:
{
    PAINTSTRUCT Paint;
    HDC DeviceContext = BeginPaint(Window, &Paint);
    int X = Paint.rcPaint.left;
    int Y = Paint.rcPaint.top;
    int Width = Paint.rcPaint.right - Paint.rcPaint.left;
    int Height = Paint.rcPaint.bottom - Paint.rcPaint.top;

    RECT ClientRect;
    GetClientRect(Window, &ClientRect);

    Win32UpdateWindow(DeviceContext, &ClientRect, X, Y, Width, Height);
    EndPaint(Window, &Paint);
} break;

default:
{
    //            OutputDebugStringA("default\n");
    Result = DefWindowProc(Window, Message, WParam, LParam);
} break;
}

return(Result);

}

 int CALLBACK
 WinMain(HINSTANCE Instance,
HINSTANCE PrevInstance,
LPSTR CommandLine,
int ShowCode)
 {
 WNDCLASS WindowClass = {};

// TODO(casey): Check if HREDRAW/VREDRAW/OWNDC still matter
WindowClass.lpfnWndProc = Win32MainWindowCallback;
WindowClass.hInstance = Instance;
//    WindowClass.hIcon;
WindowClass.lpszClassName = "HandmadeHeroWindowClass";

if (RegisterClassA(&WindowClass))
{
    HWND Window =
        CreateWindowExA(
            0,
            WindowClass.lpszClassName,
            "Handmade Hero",
            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            0,
            0,
            Instance,
            0);
    if (Window)
    {
        int XOffset = 0;
        int YOffset = 0;

        Running = true;
        while (Running)
        {
            MSG Message;
            while (PeekMessage(&Message, 0, 0, 0, PM_REMOVE))
            {
                if (Message.message == WM_QUIT)
                {
                    Running = false;
                }

                TranslateMessage(&Message);
                DispatchMessageA(&Message);
            }

            RenderWeirdGradient(XOffset, YOffset);

            HDC DeviceContext = GetDC(Window);
            RECT ClientRect;
            GetClientRect(Window, &ClientRect);
            int WindowWidth = ClientRect.right - ClientRect.left;
            int WindowHeight = ClientRect.bottom - ClientRect.top;
            Win32UpdateWindow(DeviceContext, &ClientRect, 0, 0, WindowWidth, 
 WindowHeight);
            ReleaseDC(Window, DeviceContext);

            ++XOffset;
            YOffset += 2;
        }
    }
    else
    {
        // TODO(casey): Logging
    }
}
else
{
    // TODO(casey): Logging
}

return(0);
 }

对于谁在这里要求使用callstack,它更好地形成,因为它不能作为评论工作。

  

win32_handmade.exe!Win32ResizeDIBSection(int Width,int Height)第62行C ++       win32_handmade.exe!WIN32MainWindowCallback(HWND__ * Window,unsigned int Message,unsigned int WParam,long LParam)第118行C ++       [外部代码]       win32_handmade.exe!WinMain(HINSTANCE__ * hInstance,HINSTANCE__ * PrevInstance,char * CommandLine,int ShowCode)第184行C ++       [外部代码]

0 个答案:

没有答案