|
1 | 1 | /* |
2 | | - * Copyright 2019-2023 Diligent Graphics LLC |
| 2 | + * Copyright 2019-2024 Diligent Graphics LLC |
3 | 3 | * Copyright 2015-2019 Egor Yusov |
4 | 4 | * |
5 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
@@ -60,6 +60,7 @@ class DeviceObjectBase : public ObjectBase<BaseInterface> |
60 | 60 | TBase {pRefCounters}, |
61 | 61 | m_pDevice {pDevice }, |
62 | 62 | m_Desc {ObjDesc }, |
| 63 | + m_UniqueID {pDevice != nullptr ? pDevice->GenerateUniqueId() : 0}, |
63 | 64 | m_bIsDeviceInternal{bIsDeviceInternal} |
64 | 65 | //clang-format on |
65 | 66 | { |
@@ -145,14 +146,20 @@ class DeviceObjectBase : public ObjectBase<BaseInterface> |
145 | 146 | } |
146 | 147 |
|
147 | 148 | /// Returns unique identifier |
| 149 | + |
| 150 | + /// \remarks |
| 151 | + /// This unique ID is used to unambiguously identify device object for |
| 152 | + /// tracking purposes within the device. |
| 153 | + /// Neither GL handle nor pointer could be safely used for this purpose |
| 154 | + /// as both GL reuses released handles and we pool device objects and reuse |
| 155 | + /// released ones. |
| 156 | + /// |
| 157 | + /// \note |
| 158 | + /// Objects created from different devices may have the same unique ID. |
148 | 159 | virtual Int32 DILIGENT_CALL_TYPE GetUniqueID() const override final |
149 | 160 | { |
150 | | - /// \note |
151 | | - /// This unique ID is used to unambiguously identify device object for |
152 | | - /// tracking purposes. |
153 | | - /// Neither GL handle nor pointer could be safely used for this purpose |
154 | | - /// as both GL reuses released handles and the OS reuses released pointers. |
155 | | - return m_UniqueID.GetID(); |
| 161 | + VERIFY(m_UniqueID != 0, "Unique ID is not initialized. This indicates that this device object has been created without a device"); |
| 162 | + return m_UniqueID; |
156 | 163 | } |
157 | 164 |
|
158 | 165 | /// Implementation of IDeviceObject::SetUserData. |
@@ -189,10 +196,11 @@ class DeviceObjectBase : public ObjectBase<BaseInterface> |
189 | 196 | /// Object description |
190 | 197 | ObjectDescType m_Desc; |
191 | 198 |
|
192 | | - // Template argument is only used to separate counters for |
193 | | - // different groups of objects |
194 | | - UniqueIdHelper<BaseInterface> m_UniqueID; |
195 | | - const bool m_bIsDeviceInternal; |
| 199 | + // WARNING: using static counter for unique ID is not safe |
| 200 | + // as there may be different counter instances in different |
| 201 | + // executable units (e.g. in different DLLs). |
| 202 | + const UniqueIdentifier m_UniqueID; |
| 203 | + const bool m_bIsDeviceInternal; |
196 | 204 |
|
197 | 205 | RefCntAutoPtr<IObject> m_pUserData; |
198 | 206 | }; |
|
0 commit comments