MCPcopy Create free account
hub / github.com/RavEngine/RavEngine / createInstance

Method createInstance

deps/physx/physx/source/foundation/src/PsFoundation.cpp:125–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123}
124
125Foundation* Foundation::createInstance(PxU32 version, PxErrorCallback& errc, PxAllocatorCallback& alloc)
126{
127 if(version != PX_PHYSICS_VERSION)
128 {
129 char* buffer = new char[256];
130 physx::shdfnd::snprintf(buffer, 256, "Wrong version: physics version is 0x%08x, tried to create 0x%08x",
131 PX_PHYSICS_VERSION, version);
132 errc.reportError(PxErrorCode::eINVALID_PARAMETER, buffer, __FILE__, __LINE__);
133 return 0;
134 }
135
136 if(!mInstance)
137 {
138 // if we don't assign this here, the Foundation object can't create member
139 // subobjects which require the allocator
140
141 mInstance = reinterpret_cast<Foundation*>(alloc.allocate(sizeof(Foundation), "Foundation", __FILE__, __LINE__));
142
143 if(mInstance)
144 {
145 PX_PLACEMENT_NEW(mInstance, Foundation)(errc, alloc);
146
147 PX_ASSERT(mRefCount == 0);
148 mRefCount = 1;
149
150 // skip 0 which marks uninitialized timestaps in PX_WARN_ONCE
151 mWarnOnceTimestap = (mWarnOnceTimestap == PX_MAX_U32) ? 1 : mWarnOnceTimestap + 1;
152
153 return mInstance;
154 }
155 else
156 {
157 errc.reportError(PxErrorCode::eINTERNAL_ERROR, "Memory allocation for foundation object failed.", __FILE__,
158 __LINE__);
159 }
160 }
161 else
162 {
163 errc.reportError(PxErrorCode::eINVALID_OPERATION,
164 "Foundation object exists already. Only one instance per process can be created.", __FILE__,
165 __LINE__);
166 }
167
168 return 0;
169}
170
171void Foundation::destroyInstance()
172{

Callers

nothing calls this directly

Calls 3

snprintfFunction · 0.85
reportErrorMethod · 0.45
allocateMethod · 0.45

Tested by

no test coverage detected