| 123 | } |
| 124 | |
| 125 | Foundation* 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 | |
| 171 | void Foundation::destroyInstance() |
| 172 | { |
nothing calls this directly
no test coverage detected