Error read characters of string ,unable to access memory

perseusdg 1 Reputation point
2021-02-19T19:12:41.123+00:00

I am trying to copy some buffers i read from buffer to variables in a class,
const char * buf = reinterpret_cast<const char*>(serialData);//buffer

Initializing the constructor
YoloRT *r = new YoloRT(readBUF<int>(buf), //classes
readBUF<int>(buf), //num
nullptr, //yolo
readBUF<int>(buf), //n_masks
readBUF<float>(buf), //scale_xy
readBUF<float>(buf), //nms_thresh
readBUF<int>(buf), //nms_kind
readBUF<int>(buf) //new_coords
);
for (int i = 0; i < r->n_masks; i++)
{
r->mask[i] = readBUF<dnnType>(buf);//error line
}
The error pop ups at the line mentioned, When I debug it, the error statement reads and points at buf and the value of "i" at which this error occurs changes everytime I debug it. I am confused as to what is happening here as the same code works perfectly fine on linux.It would be amazing if someone can explain why this is happening only in windows(MSVC toolchain) and any workarounds for it?

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,590 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Petrus 【KIM】 456 Reputation points
    2021-02-25T01:33:36.53+00:00

    The "YoloRT" class should allocate memory for the "mask" menber in the constructor.

        YourRT(...... int n_masks ......)
        {
            mask = new dnnType[n_masks];
        }