From 0de2bf5bac82d76a977099880f248962a91a2d1c Mon Sep 17 00:00:00 2001 From: parax0 Date: Wed, 16 Dec 2015 01:03:02 -0700 Subject: [PATCH] Going back to dynamic_cast on TResPtr --- src/Core/Resource/TResPtr.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Core/Resource/TResPtr.h b/src/Core/Resource/TResPtr.h index add736e8..ad0ca7e6 100644 --- a/src/Core/Resource/TResPtr.h +++ b/src/Core/Resource/TResPtr.h @@ -60,19 +60,16 @@ public: TResPtr& operator=(void *pPtr) { // todo: this probably crashes if you try to pass a non-CResource-derived pointer. is there a safer way? + // dynamic_cast seems like the best option for type-checking here. other methods don't catch inheritance + // eg if you have a TResPtr dynamic_cast is the only method that will allow derived resource types if (mpRes) mpRes->Release(); CResource *pRes = (CResource*) pPtr; + mpRes = dynamic_cast(pRes); - if (ResType::StaticType() == pRes->Type()) - { - mpRes = (ResType*) pRes; + if (mpRes) mpRes->Lock(); - } - - else - mpRes = nullptr; return *this; }