Attempt to convert pData provided by Direct3d11 to buffer, but error when resize window

25 views Asked by At

As the title says, the code works fine if the window is not resized, but when the window is resized, the code will make an error.

This is the code:

int width = frame.width;
int height = frame.height;
int row_pitch = frame.row_pitch;
unsigned char* data = frame.data;

int size = width * height * 4;

static unsigned char* buffer = new unsigned char[size];

int dstRowPitch = width * 4;

std::cout << height << std::endl;
for (int h = 0; h < height; h++) {
    memcpy_s(buffer + h * dstRowPitch, dstRowPitch,
        data + h * row_pitch,
        min(row_pitch, dstRowPitch));
}

I can shrink the window any way I want, but I get an error when I increase it Error occurred while executing memcpy_s

This is the original error: 0x00007FFDF60016DB (vcruntime140d.dll)处(位于 CaptureWindow.exe 中)引发的异常: 0xC0000005: 读取位置 0x000001CB28A6EB18 时发生访问冲突。

Translated into English: Exception thrown at 0x00007FFDF60016DB (vcruntime140d.dll) (located in CaptureWindow.exe) : 0xC0000005: Access conflict occurred at read location 0x000001CB28A6EB18.

System: Windows 11 Version: 26063.1

I want to be able to read the data properly when I adjust the window.

0

There are 0 answers