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