From f71fda776dc8ae794770beacccab97b772d5f2e4 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Mon, 21 Feb 2022 00:11:43 -0500 Subject: [PATCH] Protect against self-assignment in AssetPtr --- engine/asset/include/assetptr.hpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/engine/asset/include/assetptr.hpp b/engine/asset/include/assetptr.hpp index bf3b497..4dfd3c7 100644 --- a/engine/asset/include/assetptr.hpp +++ b/engine/asset/include/assetptr.hpp @@ -29,11 +29,13 @@ struct AssetPtr { } AssetPtr& operator=(const AssetPtr& rhs) { - handle = rhs.handle; - block = rhs.block; + if(&rhs != this) { + handle = rhs.handle; + block = rhs.block; - if(block != nullptr) - block->references++; + if (block != nullptr) + block->references++; + } return *this; }