| 918 | } |
| 919 | |
| 920 | ScriptingObject* Scripting::FindObject(Guid id, const MClass* type) |
| 921 | { |
| 922 | if (!id.IsValid()) |
| 923 | return nullptr; |
| 924 | PROFILE_CPU(); |
| 925 | |
| 926 | // Try to map object id |
| 927 | const auto idsMapping = ObjectsLookupIdMapping.Get(); |
| 928 | if (idsMapping) |
| 929 | { |
| 930 | idsMapping->TryGet(id, id); |
| 931 | if (!id.IsValid()) |
| 932 | return nullptr; // Skip warning if object was mapped to empty id (intentionally ignored) |
| 933 | } |
| 934 | |
| 935 | // Try to find it |
| 936 | #if USE_OBJECTS_DISPOSE_CRASHES_DEBUGGING |
| 937 | ScriptingObjectData data; |
| 938 | _objectsLocker.Lock(); |
| 939 | _objectsDictionary.TryGet(id, data); |
| 940 | _objectsLocker.Unlock(); |
| 941 | auto result = data.Ptr; |
| 942 | #else |
| 943 | ScriptingObject* result = nullptr; |
| 944 | _objectsLocker.Lock(); |
| 945 | _objectsDictionary.TryGet(id, result); |
| 946 | _objectsLocker.Unlock(); |
| 947 | #endif |
| 948 | if (result) |
| 949 | { |
| 950 | // Check type |
| 951 | if (!type || result->Is(type)) |
| 952 | return result; |
| 953 | LOG(Warning, "Found scripting object with ID={0} of type {1} that doesn't match type {2}", id, String(result->GetType().Fullname), String(type->GetFullName())); |
| 954 | LogContext::Print(LogType::Warning); |
| 955 | return nullptr; |
| 956 | } |
| 957 | |
| 958 | // Check if object can be an asset and try to load it |
| 959 | if (!type) |
| 960 | { |
| 961 | result = Content::LoadAsync<Asset>(id); |
| 962 | if (!result) |
| 963 | LOG(Warning, "Unable to find scripting object with ID={0}", id); |
| 964 | return result; |
| 965 | } |
| 966 | if (type == ScriptingObject::GetStaticClass() || type->IsSubClassOf(Asset::GetStaticClass())) |
| 967 | { |
| 968 | Asset* asset = Content::LoadAsync(id, type); |
| 969 | if (asset) |
| 970 | return asset; |
| 971 | } |
| 972 | |
| 973 | LOG(Warning, "Unable to find scripting object with ID={0}. Required type {1}", id, String(type->GetFullName())); |
| 974 | LogContext::Print(LogType::Warning); |
| 975 | return nullptr; |
| 976 | } |
| 977 |
nothing calls this directly
no test coverage detected