question

perseusdg-8733 avatar image
0 Votes"
perseusdg-8733 asked ·

Error read characters of string ,unable to access memory

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++
· 10
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

It would really amazing if someone can help me out here, I have been scratching my head over this issue for weeks..the code runs perfectly fine with gcc ,clang and icc in linux but not using MSVC

0 Votes 0 ·

Did you check if r->n_masks contains the expected value?

0 Votes 0 ·

What do you mean contains the expected value exactly? till buf throws out an error r->n_masks contains the expected value

0 Votes 0 ·
Viorel-1 avatar image Viorel-1 perseusdg-8733 ·

You have the data (serialData or buf) and you probably know the indices of bytes that contains n_mask. Then you can extract it manually in Debugger. Check if r->n_mask contains the same, correct value.

Also check if other members of r look good. (Maybe compare with the code that runs fine).

0 Votes 0 ·
Show more comments

1 Answer

PetrusKIM-2099 avatar image
0 Votes"
PetrusKIM-2099 answered ·

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

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


· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Yeah, my constructor does that ,I have shown my constructor in the comment above

0 Votes 0 ·