socket.io-client-cpp icon indicating copy to clipboard operation
socket.io-client-cpp copied to clipboard

stoi out ouf range exception when reusing unique ptr

Open AR-Vsx opened this issue 3 years ago • 0 comments

I'm trying to transmit 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.

AR-Vsx avatar Jun 08 '22 14:06 AR-Vsx