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

Function CreateResource

engine/resource/src/resource_preloader.cpp:517–676  ·  view source on GitHub ↗

CreateResource operation ends either with 1) Having created the resource and free:d all buffers => RESULT_OK + m_Resource 2) Having failed, (or created and destroyed), leaving => RESULT_SOME_ERROR + everything free:d If buffer is null it means to use the items internal buffer

Source from the content-addressed store, hash-verified

515 //
516 // If buffer is null it means to use the items internal buffer
517 static void CreateResource(HPreloader preloader, PreloadRequest* req, void* buffer, uint32_t buffer_size, uint32_t resource_size)
518 {
519 assert(req->m_LoadResult == RESULT_PENDING);
520 assert(req->m_PendingChildCount == 0);
521
522 assert(req->m_PathDescriptor.m_ResourceType);
523
524 ResourceDescriptor tmp_resource;
525 memset(&tmp_resource, 0, sizeof(tmp_resource));
526
527 ResourceType* resource_type = req->m_PathDescriptor.m_ResourceType;
528
529 // We must call CreateFunction if Preload function has been called, so always do this even when an error has occured
530 tmp_resource.m_NameHash = req->m_PathDescriptor.m_CanonicalPathHash;
531 tmp_resource.m_ReferenceCount = 1;
532 tmp_resource.m_ResourceType = resource_type;
533
534 ResourceCreateParams params;
535 params.m_Factory = preloader->m_Factory;
536 params.m_Type = resource_type;
537 params.m_Context = resource_type->m_Context;
538 params.m_PreloadData = req->m_PreloadData;
539 params.m_Resource = &tmp_resource;
540 params.m_Filename = req->m_PathDescriptor.m_InternalizedName;
541 params.m_FileSize = req->m_FileSize;
542
543 if (!buffer)
544 {
545 assert(req->m_Buffer);
546 tmp_resource.m_ResourceSizeOnDisc = req->m_BufferSize;
547 params.m_Buffer = req->m_Buffer;
548 params.m_BufferSize = req->m_BufferSize;
549 params.m_FileSize = req->m_FileSize;
550 params.m_IsBufferPartial = req->m_BufferSize != req->m_FileSize;
551 req->m_LoadResult = (Result)resource_type->m_CreateFunction(&params);
552
553 dmBlockAllocator::Free(preloader->m_BlockAllocator, req->m_Buffer, req->m_BufferSize);
554
555 req->m_Buffer = 0;
556 }
557 else
558 {
559 tmp_resource.m_ResourceSizeOnDisc = buffer_size;
560 params.m_Buffer = buffer;
561 params.m_BufferSize = buffer_size;
562 params.m_FileSize = resource_size;
563 params.m_IsBufferPartial = buffer_size != resource_size;
564 req->m_LoadResult = (Result)resource_type->m_CreateFunction(&params);
565 }
566
567 if (req->m_LoadResult == RESULT_OK)
568 {
569 if (resource_type->m_PostCreateFunction)
570 {
571 if (preloader->m_PostCreateCallbacks.Full())
572 {
573 preloader->m_PostCreateCallbacks.OffsetCapacity(MAX_PRELOADER_REQUESTS / 8);
574 }

Callers 2

PreloaderTryPruneParentFunction · 0.70
FinishLoadFunction · 0.70

Calls 10

RemoveChildrenFunction · 0.85
FindByHashFunction · 0.85
InsertResourceFunction · 0.85
FreeFunction · 0.70
assertFunction · 0.50
FullMethod · 0.45
OffsetCapacityMethod · 0.45
SetSizeMethod · 0.45
SizeMethod · 0.45

Tested by

no test coverage detected