D
D
Denis Koveshnikov2018-08-27 03:24:01
C++ / C#
Denis Koveshnikov, 2018-08-27 03:24:01

Why does this realloc function call throw an exception?

Actually what is the reason? Starting from the second line

if ((rwOBJECT_VERTEX_UV & g_Clump->GeometryList.Geometry[g_Clump->GeometryList.GeometryCount - 1].Data.Header.Flags1) == rwOBJECT_VERTEX_UV){
      g_Clump->GeometryList.Geometry[g_Clump->GeometryList.GeometryCount - 1].Data.UV =
        (Vector2f*)realloc(
          g_Clump->GeometryList.Geometry[g_Clump->GeometryList.GeometryCount - 1].Data.UV,
          sizeof(Vector2f)*g_Clump->GeometryList.Geometry[g_Clump->GeometryList.GeometryCount - 1].Data.Header.VertexCount
          );//SetLength(UV, Header.VertexCount);
      fread(&g_Clump->GeometryList.Geometry[g_Clump->GeometryList.GeometryCount - 1].Data.UV[0], 
        1,8* g_Clump->GeometryList.Geometry[g_Clump->GeometryList.GeometryCount - 1].Data.Header.VertexCount,
        stream);
    }

5b8343774383c981693935.png
If the code has passed to the second line, then all pointers are normal. Something similar passes normally, for example, such a construction does not cause errors.
g_Clump->GeometryList.Geometry = (DFFGeometry*)realloc(g_Clump->GeometryList.Geometry, g_Clump->GeometryList.GeometryCount);

I tried to play around with malloc, changing the size of the allocated memory, he is ready to allocate bytes, and when he asked for 40, he felt bad and I got an exception, where can I dig here? what kind of game?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2018-08-27
@jcmvbkbc

where can you dig here? what kind of game?

Probably broke a bunch. Dig towards memory usage validation -- valgrind, asan, duma, electric fence, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question