Janny8

Hi, I have encountered a strange problem: When I used DirectShow to paly memory file I got an error:"First-chance exception in Peer.exe (XVIDCORE.DLL): 0xC0000005: Access Violation.".

I rewrite the sample MEMFile to play media streams in a buffer. I used Pull mode.

First I pre-buffered 20M data and I'm sure these data is all right ready there,then, In CMemStream::Read I copy my data to DS's pbBuffer. But when it played for a while -abut several minutes- I got the above error, and the error position is not always the same every time.

I am very wildered about that. I have searched a lot but no result. If anyone has encountered the similar problem please give me a hand. Thanks a lot!

I list some code here for reference:

=========

HRESULT CMemStream::Read(PBYTE pbBuffer,
DWORD dwBytesToRead,
BOOL bAlign,
LPDWORD pdwBytesRead)
{
CAutoLock lck(&m_csLock);
DWORD dwReadLength = 0;

/* Wait until the bytes are here! */
DWORD dwTime = timeGetTime();
if (m_llPosition + dwBytesToRead > m_llLength) {
dwReadLength = (DWORD)(m_llLength - m_llPosition);
} else {
dwReadLength = dwBytesToRead;
}

DWORD dwTimeToArrive =
((DWORD)m_llPosition + dwReadLength) / m_dwKBPerSec;
if (dwTime - m_dwTimeStart < dwTimeToArrive) {
Sleep(dwTimeToArrive - dwTime + m_dwTimeStart);


// copy data from my buffer to DS's buffer

int iPos = m_llPosition % BUFFER_SIZE;
if (iPos+dwReadLength > BUFFER_SIZE) {
memcpy((PVOID)pbBuffer, (PVOID)(m_pbData + iPos), (BUFFER_SIZE-iPos) );
memcpy((PVOID)pbBuffer, (PVOID)(m_pbData), (dwReadLength - (BUFFER_SIZE-iPos)) );
} else {
memcpy((PVOID)pbBuffer, (PVOID)(m_pbData + iPos), dwReadLength);
}

m_llPosition += dwReadLength;
*pdwBytesRead = dwReadLength;


// buffer when need

// ...


return S_OK;
}




Re: DirectShow Development got 0xC0000005: Access Violatio while play memory file with DirectShow

LGS

If you let the program continue running, does it run correctly Some code throws 1st chance exceptions, then catches them.





Re: DirectShow Development got 0xC0000005: Access Violatio while play memory file with DirectShow

Janny8

I got sth from your answer.

You mean that this error occurred ocassionally and can be avoid by try..catch

My phenomenon is: When error occurred the program is down. But if I catch the exception as you said I could solve these problem maybe. I will try it and tell you the result. Thanks!!






Re: DirectShow Development got 0xC0000005: Access Violatio while play memory file with DirectShow

Janny8

I modified the code in OnPlay() method like this:

try
{
hr = m_pMC->Run();
}
catch (...)
{

hr = m_pMC->Run();

#ifdef _PPMP_DEBUG
TRACE("PeerClient Error: Run() exception.\n");
#endif
}

But the problem remains the same. Maybe I have modified the wrong place

And when I play the same media from file directly It goes well.






Re: DirectShow Development got 0xC0000005: Access Violatio while play memory file with DirectShow

Janny8

I had another found--

When I use DS's sample--MEMFile to play the same file in memory, the same problem occurred!

Then It sames the error has nothing with my buffer. I became even more bewildered Sad






Re: DirectShow Development got 0xC0000005: Access Violatio while play memory file with DirectShow

LGS

No, what I am saying is that since it is only a *first* chance exception, that *they* are catching it. First chance exceptions in other people's code should be ignored.




Re: DirectShow Development got 0xC0000005: Access Violatio while play memory file with DirectShow

Janny8

I should make it more clear.

"First-chance exception in Peer.exe (XVIDCORE.DLL): 0xC0000005: Access Violation" is from VC's output window while I DEBUG(F5) the application Peer.exe

And, while I RUN the appication's debug version I got a information dialog which say:"Unhandled exception in Peer(XVIDCORE.DLL) : 0xC0000005: Access Violation". After I click the OK buttion the arrow point to the following line

in XVID's source file: decoder.c

mb->b_mvs[0] = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] = zeromv;

And the call stack is :

decoder_bframe(DECODER * 0x0e180080, Bitstream * 0x0d85fb70, int 28, int 4, int 1) line 1385 + 6 bytes
decoder_decode(DECODER * 0x0e180080, xvid_dec_frame_t * 0x0d85fc40, xvid_dec_stats_t * 0x0d85fc20) line 1715 + 25 bytes
xvid_decore(void * 0x0e180080, int 2, void * 0x0d85fc40, void * 0x0d85fc20) line 825 + 17 bytes
FFDSHOW! 04d19224()