'stoi out ouf range exception when reusing unique ptr
I'm trying to transmitt a draco encoded point cloud via socket.io.
In the first iteration everything is fine but in every following iteration abort() is being called, because I get an out of range exception in _NODISCARD inline int stoi
.
for (int i = 0; i < count; i++)
{
//get pointcloud from kinect source
cwipc* capturedPC = ts->get();
cwipcH.CopyPointsToStruct(capturedPC);
//create draco point cloud from captured pointcloud (this throws the out of range exception on the second iteration)
std::unique_ptr<draco::PointCloud> pc = dracoH.BuildPointCloud(capturedPC, cwipcH);
//Write the encoder buffer with position quantization, compression speed and decompression speed
eBuff = dracoH.GetEncoderBuffer(move(pc), 13, 10, 10);
std::cout << "Buffer size " << eBuff.size() << "\n";
//copy encoder buffer to new char*
size_t size = eBuff.size();
const char* eBuffData = eBuff.data();
char* eBuffCpy = new char[size];
strncpy_s(eBuffCpy, sizeof(eBuffData), eBuffData, size);
//create shared pointer for pointcloud payload
std::shared_ptr<std::string> payload = std::make_shared<std::string>(eBuffData,size);
//transmitt payload
client.socket()->emit("Encoder Buffer", payload);
//free memory
capturedPC->free();
eBuff.Clear();
payload.reset();
pc.reset();
}
I've tried copying the encoder Buffer to a new char*, but the error still persits.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|