Correctly rollback the previous rollback

This commit is contained in:
Alexander Bock
2016-07-07 13:49:57 +02:00
parent 6e9d299dda
commit e3a1b775fd
2 changed files with 16 additions and 6 deletions

View File

@@ -28,6 +28,7 @@
#include <ghoul/opengl/ghoul_gl.h>
#include <ghoul/misc/assert.h>
#include <memory>
#include <stdint.h>
#include <vector>
@@ -43,6 +44,8 @@ public:
SyncBuffer(size_t n);
~SyncBuffer();
void encode(const std::string& s) {
const size_t size = sizeof(char) * s.size() + sizeof(int32_t);
ghoul_assert(_encodeOffset + size < _n, "");
@@ -107,7 +110,7 @@ private:
size_t _encodeOffset;
size_t _decodeOffset;
std::vector<char> _dataStream;
sgct::SharedVector<char> _synchronizationBuffer;
std::unique_ptr<sgct::SharedVector<char>> _synchronizationBuffer;
};
} // namespace openspace

View File

@@ -32,22 +32,29 @@ SyncBuffer::SyncBuffer(size_t n)
: _n(n)
, _encodeOffset(0)
, _decodeOffset(0)
, _synchronizationBuffer(new sgct::SharedVector<char>())
{
_dataStream.resize(_n);
}
SyncBuffer::~SyncBuffer() {
// The destructor is defined here, so that the otherwise default inlined destructor is
// not created (which would make it impossible to use a forward declaration with
// unique_ptr
}
void SyncBuffer::write() {
_synchronizationBuffer.setVal(_dataStream);
sgct::SharedData::instance()->writeVector(&_synchronizationBuffer);
_synchronizationBuffer->setVal(_dataStream);
sgct::SharedData::instance()->writeVector(_synchronizationBuffer.get());
_encodeOffset = 0;
_decodeOffset = 0;
}
void SyncBuffer::read() {
sgct::SharedData::instance()->readVector(&_synchronizationBuffer);
_dataStream = std::move(_synchronizationBuffer.getVal());
sgct::SharedData::instance()->readVector(_synchronizationBuffer.get());
_dataStream = std::move(_synchronizationBuffer->getVal());
_encodeOffset = 0;
_decodeOffset = 0;
}
} // namespace openspace
} // namespace openspace