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

Function AllocInstance

engine/gameobject/src/gameobject/gameobject.cpp:784–806  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

782 }
783
784 static HInstance AllocInstance(Prototype* proto, const char* prototype_name) {
785 // Count number of component userdata fields required
786 uint32_t component_instance_userdata_count = 0;
787 for (uint32_t i = 0; i < proto->m_ComponentCount; ++i)
788 {
789 Prototype::Component* component = &proto->m_Components[i];
790 ComponentType* component_type = component->m_Type;
791 if (!component_type)
792 {
793 dmLogError("Internal error. Component type #%d for '%s' not found.", i, prototype_name);
794 assert(false);
795 }
796 if (component_type->m_InstanceHasUserData)
797 component_instance_userdata_count++;
798 }
799
800 uint32_t component_userdata_size = sizeof(((Instance*)0)->m_ComponentInstanceUserData[0]);
801 // NOTE: Allocate actual Instance with *all* component instance user-data accounted
802 void* instance_memory = ::operator new (sizeof(Instance) + component_instance_userdata_count * component_userdata_size);
803 Instance* instance = new(instance_memory) Instance(proto);
804 instance->m_ComponentInstanceUserDataCount = component_instance_userdata_count;
805 return instance;
806 }
807
808 static void DeallocInstance(HInstance instance) {
809 instance->~Instance();

Callers 2

NewInstanceFunction · 0.85
RecreateInstanceFunction · 0.85

Calls 2

operator newFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected