Quick question.
When I try to read from CStdioFile.Read(void* Buffer, int nRead) i get a thrown exception. I'm sure this works in VS2003, but now it throws an exception in SetString
bool CObjLoader::Open(CString &File, vector<float> &Vertex, vector<int> &Index, vector<float> &Normal, vector<float> &Texture)
{
CStdioFile ObjFile;
CFileException Exception;
int Length;
int Position = 0;
try
{
ObjFile.Open(File, CStdioFile::modeRead | CStdioFile::shareExclusive | CStdioFile::typeText, &Exception);
}
catch (CFileException Exception)
{
int Cause = Exception.m_cause;
// to do : advanced recovery...
}
CString Buffer;
Length = (int)ObjFile.GetLength();
vector<char> vBuffer;
vBuffer.resize(Length);
ObjFile.Read(&vBuffer, Length);
ObjFile.Close();
m_pHeader.clear();
Count(TypeVertex);
Count(TypeIndex);
Count(TypeNormal);
Count(TypeTexture);
Convert_FloatStream(TypeVertex, Vertex);
Convert_IntStream(Index);
Convert_FloatStream(TypeNormal, Normal);
if (m_pHeader.back() > 0)
Convert_FloatStream(TypeTexture, Texture);
return true;
}
The exception thrown is in...
"Unhandled exception at 0x7c81eb33 in objmfc.exe: Microsoft C++ exception: CFileException at memory location 0x0012fba8.."
void SetString( __in_ecount(nLength) PCXSTR pszSrc, __in int nLength )
{
if( nLength == 0 )
{
Empty();
}
else
{
// It is possible that pszSrc points to a location inside of our
// buffer. GetBuffer() might change m_pszData if (1) the buffer
// is shared or (2) the buffer is too small to hold the new
// string. We detect this aliasing, and modify pszSrc to point
// into the newly allocated buffer instead.
if(pszSrc == NULL)
AtlThrow(E_INVALIDARG);
UINT nOldLength = GetLength();
UINT_PTR nOffset = pszSrc-GetString();
// If 0 <= nOffset <= nOldLength, then pszSrc points into our
// buffer
PXSTR pszBuffer = GetBuffer( nLength );
if( nOffset <= nOldLength )
{
#if _SECURE_ATL
CopyCharsOverlapped( pszBuffer, nLength,
pszBuffer+nOffset, nLength );
#else
CopyCharsOverlapped( pszBuffer, pszBuffer+nOffset, nLength );
#endif
}
else
{
#if _SECURE_ATL
CopyChars( pszBuffer, nLength, pszSrc, nLength );
#else
CopyChars( pszBuffer, pszSrc, nLength );
#endif
}
ReleaseBufferSetLength( nLength ); <-- references this line
}
}
I get the feeling its something to do with the new secure code that MS has implemented in VS2005.
Thanks
Craig