Going back to dynamic_cast on TResPtr
This commit is contained in:
parent
824d23efc1
commit
0de2bf5bac
|
@ -60,19 +60,16 @@ public:
|
||||||
TResPtr<ResType>& operator=(void *pPtr)
|
TResPtr<ResType>& operator=(void *pPtr)
|
||||||
{
|
{
|
||||||
// todo: this probably crashes if you try to pass a non-CResource-derived pointer. is there a safer way?
|
// 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<CResource> dynamic_cast is the only method that will allow derived resource types
|
||||||
if (mpRes)
|
if (mpRes)
|
||||||
mpRes->Release();
|
mpRes->Release();
|
||||||
|
|
||||||
CResource *pRes = (CResource*) pPtr;
|
CResource *pRes = (CResource*) pPtr;
|
||||||
|
mpRes = dynamic_cast<ResType*>(pRes);
|
||||||
|
|
||||||
if (ResType::StaticType() == pRes->Type())
|
if (mpRes)
|
||||||
{
|
|
||||||
mpRes = (ResType*) pRes;
|
|
||||||
mpRes->Lock();
|
mpRes->Lock();
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
mpRes = nullptr;
|
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue