Reputation: 2486
I am developing a class for displaying 10-bit video streams using D3D11. The solution I went for was to render each frame as a texture to a quad. As such I have a function for updating the frame/texture from a YUV surface:
void tenBitDisplay::SetTextureData(short int *yuvData) {
unsigned int size = m_width * m_height, chromaSize;
short int y1, y2, y3, y4, u, v, r, g, b;
DWORD *data;
chromaSize = size * 0.25;
data = new DWORD[size];
for(unsigned int k = 0, j = 0; k < size; k += 2, j++) {
y1 = yuvData[k];
y2 = yuvData[k + 1];
y3 = yuvData[k + m_width];
y4 = yuvData[k + m_width + 1];
u = yuvData[size + j];
v = yuvData[size + chromaSize + j];
convertYUV(y1, u, v, &r, &g, &b);
packRGB(data, r, g, b, k);
convertYUV(y2, u, v, &r, &g, &b);
packRGB(data, r, g, b, k + 1);
convertYUV(y3, u, v, &r, &g, &b);
packRGB(data, r, g, b, k + m_width);
convertYUV(y4, u, v, &r, &g, &b);
packRGB(data, r, g, b, k + m_width + 1);
if (k!=0 && (k+2) % m_width == 0)
k += m_width;
}
if (m_pTexture2D != NULL) {
m_pImmediateContext->UpdateSubresource(m_pTexture2D, 0, NULL, data, m_width * 4, 0);
}
free(data);
}
Everything executes fine up until it reaches the m_pImmediateContext->UpdateSubresource(m_pTexture2D, 0, NULL, data, m_width * 4, 0);
call. At some point during execution of this method, the following exception is thrown:
First-chance exception at 0x751EC41F (KernelBase.dll) in app.exe: 0x0000087D (parameters: 0x00000000, 0x0273D328, 0x0273C760).
If there is a handler for this exception, the program may be safely continued.
I am guessing this is a problem with the heap, stack or something else to do with memory. I just can't figure out what precisely, and I have never encountered such an issue and don't really have much knowledge about where to start with debugging it. I have checked the preceding loop to make sure there is no overrun on the buffer and everything is fine.
EDIT: I forgot to mention that I had basically the same code running fine in a different application (which just loaded YUV files directly) before I moved it into the video decoding application.
Upvotes: 1
Views: 617
Reputation: 2486
I found the problem. I was updating the texture in one thread whilst another thread was calling the render method. This caused the threads to clash over the texture object. I implemented a mutex and it seems to work okay now.
Upvotes: 1