git repos / blockattack-game

commit 906183f8

sago007 · 2018-03-26 13:14
906183f810e0d711a684012895c7feab5958a8e4 patch · browse files
parent d91e73632b6579237eb45693a7843541e504c9b6

Ensure that we create a copy of the internal data when copying SagoTextField

Changed files

M source/code/sago/SagoTextField.cpp before
diff --git a/source/code/sago/SagoTextField.cpp b/source/code/sago/SagoTextField.cpp index a6c795b..7add13a 100644 --- a/source/code/sago/SagoTextField.cpp +++ b/source/code/sago/SagoTextField.cpp
@@ -84,13 +84,19 @@ SagoTextField::SagoTextField(SagoTextField&& o) noexcept {
}
SagoTextField& SagoTextField::operator=(const SagoTextField& base) {
- data = base.data;
- //Copy all data but do not reuse the cache as it would result in a double free
- data->outlineTextSurface = nullptr;
- data->outlineTexture = nullptr;
- data->textSurface = nullptr;
- data->texture = nullptr;
- return *this;
+ data = new SagoTextFieldData();
+ try {
+ *data = *(base.data);
+ //Copy all data but do not reuse the cache as it would result in a double free
+ data->outlineTextSurface = nullptr;
+ data->outlineTexture = nullptr;
+ data->textSurface = nullptr;
+ data->texture = nullptr;
+ return *this;
+ } catch (...) {
+ delete data;
+ throw;
+ }
}
SagoTextField::~SagoTextField() {