MCPcopy Create free account
hub / github.com/defold/defold / FinishLoad

Function FinishLoad

engine/resource/src/resource_preloader.cpp:705–757  ·  view source on GitHub ↗

Ends the Load part of the resource and handles the result of the load It will create the resource if it has no children, otherwise it will copy the loaded buffer for later use when all the children has been created. Returns true if the resource was created

Source from the content-addressed store, hash-verified

703 //
704 // Returns true if the resource was created
705 static bool FinishLoad(HPreloader preloader, PreloadRequest* req, dmLoadQueue::LoadResult& load_result, void* buffer, uint32_t buffer_size, uint32_t resource_size)
706 {
707 // Pop any hints the load/preload of the item that may have been generated
708 PopHints(preloader);
709
710 // Propagate errors
711 if (load_result.m_LoadResult != RESULT_OK)
712 {
713 req->m_LoadResult = load_result.m_LoadResult;
714 }
715 else if (load_result.m_PreloadResult != RESULT_OK)
716 {
717 req->m_LoadResult = load_result.m_PreloadResult;
718 }
719
720 // On error remove all children
721 if (req->m_LoadResult != RESULT_PENDING)
722 {
723 RemoveChildren(preloader, req);
724 RemoveFromParentPendingCount(preloader, req);
725 }
726
727 req->m_PreloadData = load_result.m_PreloadData;
728
729 bool created_resource = false;
730
731 // If no children, do the create step immediately with the buffer in place
732 if (req->m_FirstChild == -1)
733 {
734 if (req->m_LoadResult == RESULT_PENDING)
735 {
736 // Create the resource using the loading buffer directly.
737 CreateResource(preloader, req, buffer, buffer_size, resource_size);
738 created_resource = true;
739 }
740 UnmarkPathInProgress(preloader, &req->m_PathDescriptor);
741 dmLoadQueue::FreeLoad(preloader->m_LoadQueue, req->m_LoadRequest);
742 req->m_LoadRequest = 0;
743
744 PreloaderTryPruneParent(preloader, req);
745 }
746 else
747 {
748 // Keep the loaded bytes until we have loaded all children
749 req->m_Buffer = dmBlockAllocator::Allocate(preloader->m_BlockAllocator, buffer_size);
750 memcpy(req->m_Buffer, buffer, buffer_size);
751 req->m_BufferSize = buffer_size;
752 req->m_FileSize = resource_size;
753 dmLoadQueue::FreeLoad(preloader->m_LoadQueue, req->m_LoadRequest);
754 req->m_LoadRequest = 0;
755 }
756 return created_resource;
757 }
758
759 static bool DoPreloaderUpdateOneReq(HPreloader preloader, TRequestIndex index, PreloadRequest* req);
760

Callers 1

DoPreloaderUpdateOneReqFunction · 0.85

Calls 8

PopHintsFunction · 0.85
RemoveChildrenFunction · 0.85
UnmarkPathInProgressFunction · 0.85
PreloaderTryPruneParentFunction · 0.85
AllocateFunction · 0.85
CreateResourceFunction · 0.70
FreeLoadFunction · 0.50

Tested by

no test coverage detected