Here is my code:
int LoadVerts(char *s_fName, OURCUSTOMVERTEX *p_Verts, short *p_Indices)
{
long i_CountVerts;
long i_CountInds;
unsigned char buffer[sizeof(OURCUSTOMVERTEX)];
basic_ifstream<unsigned char> f_DataFile;
f_DataFile.open(s_fName, std::ios_base::in | std::ios_base::binary);
f_DataFile.read(buffer, sizeof(long));
memcpy(&i_CountVerts, buffer, sizeof(long));
f_DataFile.read(buffer, sizeof(long));
memcpy(&i_CountInds, buffer, sizeof(long));
if ((p_Verts = (OURCUSTOMVERTEX *)realloc(p_Verts, sizeof(OURCUSTOMVERTEX) * i_CountVerts)) == NULL)
exit( 1 );
if ((p_Indices = (short *)realloc(p_Indices, sizeof(short) * i_CountInds)) == NULL)
exit( 1 );
for (int temp = 0; temp < i_CountVerts; temp++)
{
f_DataFile.read(buffer, sizeof(OURCUSTOMVERTEX));
memcpy(&p_Verts[temp], buffer, sizeof(OURCUSTOMVERTEX));
}
for (int temp2 = 0; temp2 < i_CountInds; temp2++)
{
f_DataFile.read(buffer, sizeof(short));
memcpy(&p_Indices[temp2], buffer, sizeof(short));
}
f_DataFile.close();
return 0;
}
My issue is coming in at the following lines:
if ((p_Verts = (OURCUSTOMVERTEX *)realloc(p_Verts, sizeof(OURCUSTOMVERTEX) * i_CountVerts)) == NULL)
exit( 1 );
if ((p_Indices = (short *)realloc(p_Indices, sizeof(short) * i_CountInds)) == NULL)
exit( 1 );
This is the error I am getting after a successful build and the program is running:
Windows has triggered a breakpoint in saveverts.exe.
This may be due to a corruption of the heap, and indicates a bug in saveverts.exe or any of the DLLs it has loaded.
The output window may have more diagnostic information
After a bit of lengthy chasing.... i have turned up empty handed with my focus on a function in istream called "_Read_s", which I am confident is not the problem. SOOOO.... I am looking for Help, advice, or Insight.
SHORT DESC: This function should receive 2 arrays of different types. During the meat of the code it should load a file, read from the file the first two long values to get the lengths of each array. it should reset the arrays to the new lengths to allow for input of the values from the files. After the values are filled in the newly sized arrays, these new arrays and new values should be accessible from the calling procedure, in this case WinMain().
Thanks in advance.