| 322 | } |
| 323 | |
| 324 | static Result PreloadPathDescriptor(HPreloader preloader, TRequestIndex parent, const PathDescriptor& path_descriptor) |
| 325 | { |
| 326 | // Quick deduplication, check if the child is already listed under the current parent |
| 327 | TRequestIndex child = preloader->m_Request[parent].m_FirstChild; |
| 328 | while (child != -1) |
| 329 | { |
| 330 | if (preloader->m_Request[child].m_PathDescriptor.m_NameHash == path_descriptor.m_NameHash) |
| 331 | { |
| 332 | return RESULT_ALREADY_REGISTERED; |
| 333 | } |
| 334 | child = preloader->m_Request[child].m_NextSibling; |
| 335 | } |
| 336 | |
| 337 | if (!preloader->m_FreelistSize) |
| 338 | { |
| 339 | // Preload queue is exhausted; this is not fatal, it just means the resource will be loaded |
| 340 | // inside the main thread which may cause stuttering |
| 341 | return RESULT_OUT_OF_MEMORY; |
| 342 | } |
| 343 | |
| 344 | TRequestIndex new_req = preloader->m_Freelist[--preloader->m_FreelistSize]; |
| 345 | PreloadRequest* req = &preloader->m_Request[new_req]; |
| 346 | memset(req, 0, sizeof(PreloadRequest)); |
| 347 | req->m_PathDescriptor = path_descriptor; |
| 348 | req->m_FirstChild = -1; |
| 349 | req->m_LoadResult = RESULT_PENDING; |
| 350 | |
| 351 | PreloaderTreeInsert(preloader, new_req, parent); |
| 352 | |
| 353 | // Check for recursive resources, if it is, mark with loop error, the recursive load result will |
| 354 | // be checked for in the PreloaderUpdateOneItem and the result will be propagated to the resource |
| 355 | // preloaded creator. |
| 356 | TRequestIndex go_up = parent; |
| 357 | while (go_up != -1) |
| 358 | { |
| 359 | if (preloader->m_Request[go_up].m_PathDescriptor.m_CanonicalPathHash == path_descriptor.m_CanonicalPathHash) |
| 360 | { |
| 361 | req->m_LoadResult = RESULT_RESOURCE_LOOP_ERROR; |
| 362 | assert(parent != -1); |
| 363 | assert(preloader->m_Request[parent].m_PendingChildCount > 0); |
| 364 | preloader->m_Request[parent].m_PendingChildCount -= 1; |
| 365 | break; |
| 366 | } |
| 367 | go_up = preloader->m_Request[go_up].m_Parent; |
| 368 | } |
| 369 | return RESULT_OK; |
| 370 | } |
| 371 | |
| 372 | static bool PopHints(HPreloader preloader) |
| 373 | { |
no test coverage detected