void reset(void) { PX_FREE(mPrimitives); PX_FREE(mData); mData = NULL; mPrimitives = NULL; }
ApexResourceProvider::NameSpace::~NameSpace() { // Free up all collision chains in the hash table for (uint32_t i = 0 ; i < HashSize ; i++) { while (hash[i]) { const char* entry = hash[i]; const entryHeader* hdr = (const entryHeader*) entry; const char* next = hdr->nextEntry; PX_FREE((void*) entry); hash[i] = next; } } PX_FREE(mNameSpace); }
Thread::~Thread() { if(mImpl->state == ThreadImpl::Started) kill(); CloseHandle(mImpl->thread); PX_FREE(mImpl); }
MAT *m_inverse(const MAT *A, MAT *out) { unsigned int i; char MatrixTempBuffer[ 4000 ]; VEC *tmp = VNULL, *tmp2 = VNULL; MAT *A_cp = MNULL; PERM *pivot = PNULL; if ( ! A ) error(E_NULL,"m_inverse"); if ( A->m != A->n ) error(E_SQUARE,"m_inverse"); if ( ! out || out->m < A->m || out->n < A->n ) out = m_resize(out,A->m,A->n); if( SET_MAT_SIZE( A->m, A->n ) < 1000 ) mat_get( &A_cp, (void *)( MatrixTempBuffer + 2000 ), A->m, A->n ); else A_cp = matrix_get( A->m, A->n ); A_cp = m_copy( A, A_cp ); if( SET_VEC_SIZE( A->m ) < 1000 ) { vec_get( &tmp, (void *)MatrixTempBuffer, A->m ); vec_get( &tmp2, (void *)(MatrixTempBuffer + 1000), A->m ); } else { tmp = v_get( A->m ); tmp2 = v_get( A->m ); } if( SET_PERM_SIZE( A->m ) < 1000 ) { perm_get( &pivot, (void *)( MatrixTempBuffer + 3000 ), A->m ); } else { pivot = px_get( A->m ); } LUfactor(A_cp,pivot); //tracecatch_matrix(LUfactor(A_cp,pivot),"m_inverse"); for ( i = 0; i < A->n; i++ ){ v_zero(tmp); tmp->ve[i] = 1.0; LUsolve(A_cp,pivot,tmp,tmp2); //tracecatch_matrix(LUsolve(A_cp,pivot,tmp,tmp2),"m_inverse"); set_col(out,i,tmp2); } if( tmp != (VEC *)(MatrixTempBuffer ) ) // память выделялась, надо освободить V_FREE(tmp); if( tmp2 != (VEC *)(MatrixTempBuffer + 1000) ) // память выделялась, надо освободить V_FREE(tmp2); if( A_cp != (MAT *)(MatrixTempBuffer + 2000) ) // память выделялась, надо освободить M_FREE(A_cp); if( pivot != (PERM *)(MatrixTempBuffer + 3000) ) // память выделялась, надо освободить PX_FREE( pivot ); return out; }
DefaultCpuDispatcher::~DefaultCpuDispatcher() { for (PxU32 i = 0; i < mNumThreads; ++i) { mWorkerThreads[i].signalQuit(); } mShuttingDown = true; mWorkReady.set(); for (PxU32 i = 0; i < mNumThreads; ++i) { mWorkerThreads[i].waitForQuit(); } for (PxU32 i = 0; i < mNumThreads; ++i) { mWorkerThreads[i].~CpuWorkerThread(); } PX_FREE(mWorkerThreads); }
MAT *m_inverse(const MAT *A, MAT *out) #endif { int i; STATIC VEC *tmp = VNULL, *tmp2 = VNULL; STATIC MAT *A_cp = MNULL; STATIC PERM *pivot = PNULL; if ( ! A ) error(E_NULL,"m_inverse"); if ( A->m != A->n ) error(E_SQUARE,"m_inverse"); if ( ! out || out->m < A->m || out->n < A->n ) out = m_resize(out,A->m,A->n); A_cp = m_resize(A_cp,A->m,A->n); A_cp = m_copy(A,A_cp); tmp = v_resize(tmp,A->m); tmp2 = v_resize(tmp2,A->m); pivot = px_resize(pivot,A->m); MEM_STAT_REG(A_cp,TYPE_MAT); MEM_STAT_REG(tmp, TYPE_VEC); MEM_STAT_REG(tmp2,TYPE_VEC); MEM_STAT_REG(pivot,TYPE_PERM); tracecatch(LUfactor(A_cp,pivot),"m_inverse"); for ( i = 0; i < A->n; i++ ) { v_zero(tmp); tmp->ve[i] = 1.0; tracecatch(LUsolve(A_cp,pivot,tmp,tmp2),"m_inverse"); set_col(out,i,tmp2); } #ifdef THREADSAFE V_FREE(tmp); V_FREE(tmp2); M_FREE(A_cp); PX_FREE(pivot); #endif return out; }
void Gu::TriangleMesh::debugVisualize( Cm::RenderOutput& out, const PxTransform& pose, const PxMeshScale& scaling, const PxBounds3& cullbox, const PxU64 mask, const PxReal fscale, const PxU32 numMaterials) const { PX_UNUSED(numMaterials); //bool cscale = !!(mask & ((PxU64)1 << PxVisualizationParameter::eCULL_BOX)); const PxU64 cullBoxMask = PxU64(1) << PxVisualizationParameter::eCULL_BOX; bool cscale = ((mask & cullBoxMask) == cullBoxMask); const PxMat44 midt(PxIdentity); const Cm::Matrix34 absPose(PxMat33(pose.q) * scaling.toMat33(), pose.p); PxU32 nbTriangles = getNbTrianglesFast(); const PxU32 nbVertices = getNbVerticesFast(); const PxVec3* vertices = getVerticesFast(); const void* indices = getTrianglesFast(); const PxDebugColor::Enum colors[] = { PxDebugColor::eARGB_BLACK, PxDebugColor::eARGB_RED, PxDebugColor::eARGB_GREEN, PxDebugColor::eARGB_BLUE, PxDebugColor::eARGB_YELLOW, PxDebugColor::eARGB_MAGENTA, PxDebugColor::eARGB_CYAN, PxDebugColor::eARGB_WHITE, PxDebugColor::eARGB_GREY, PxDebugColor::eARGB_DARKRED, PxDebugColor::eARGB_DARKGREEN, PxDebugColor::eARGB_DARKBLUE, }; const PxU32 colorCount = sizeof(colors)/sizeof(PxDebugColor::Enum); if(cscale) { const Gu::Box worldBox( (cullbox.maximum + cullbox.minimum)*0.5f, (cullbox.maximum - cullbox.minimum)*0.5f, PxMat33(PxIdentity)); // PT: TODO: use the callback version here to avoid allocating this huge array PxU32* results = reinterpret_cast<PxU32*>(PX_ALLOC_TEMP(sizeof(PxU32)*nbTriangles, "tmp triangle indices")); LimitedResults limitedResults(results, nbTriangles, 0); Midphase::intersectBoxVsMesh(worldBox, *this, pose, scaling, &limitedResults); nbTriangles = limitedResults.mNbResults; if (fscale) { const PxU32 fcolor = PxU32(PxDebugColor::eARGB_DARKRED); for (PxU32 i=0; i<nbTriangles; i++) { const PxU32 index = results[i]; PxVec3 wp[3]; getTriangle(*this, index, wp, vertices, indices, absPose, has16BitIndices()); const PxVec3 center = (wp[0] + wp[1] + wp[2]) / 3.0f; PxVec3 normal = (wp[0] - wp[1]).cross(wp[0] - wp[2]); PX_ASSERT(!normal.isZero()); normal = normal.getNormalized(); out << midt << fcolor << Cm::DebugArrow(center, normal * fscale); } } if (mask & (PxU64(1) << PxVisualizationParameter::eCOLLISION_SHAPES)) { const PxU32 scolor = PxU32(PxDebugColor::eARGB_MAGENTA); out << midt << scolor; // PT: no need to output this for each segment! PxDebugLine* segments = out.reserveSegments(nbTriangles*3); for(PxU32 i=0; i<nbTriangles; i++) { const PxU32 index = results[i]; PxVec3 wp[3]; getTriangle(*this, index, wp, vertices, indices, absPose, has16BitIndices()); segments[0] = PxDebugLine(wp[0], wp[1], scolor); segments[1] = PxDebugLine(wp[1], wp[2], scolor); segments[2] = PxDebugLine(wp[2], wp[0], scolor); segments+=3; } } if ((mask & (PxU64(1) << PxVisualizationParameter::eCOLLISION_EDGES)) && mExtraTrigData) visualizeActiveEdges(out, *this, nbTriangles, results, absPose, midt); PX_FREE(results); } else { if (fscale) { const PxU32 fcolor = PxU32(PxDebugColor::eARGB_DARKRED); for (PxU32 i=0; i<nbTriangles; i++) { PxVec3 wp[3]; getTriangle(*this, i, wp, vertices, indices, absPose, has16BitIndices()); const PxVec3 center = (wp[0] + wp[1] + wp[2]) / 3.0f; PxVec3 normal = (wp[0] - wp[1]).cross(wp[0] - wp[2]); PX_ASSERT(!normal.isZero()); normal = normal.getNormalized(); out << midt << fcolor << Cm::DebugArrow(center, normal * fscale); } } if (mask & (PxU64(1) << PxVisualizationParameter::eCOLLISION_SHAPES)) { PxU32 scolor = PxU32(PxDebugColor::eARGB_MAGENTA); out << midt << scolor; // PT: no need to output this for each segment! PxVec3* transformed = reinterpret_cast<PxVec3*>(PX_ALLOC(sizeof(PxVec3)*nbVertices, "PxVec3")); for(PxU32 i=0;i<nbVertices;i++) transformed[i] = absPose.transform(vertices[i]); PxDebugLine* segments = out.reserveSegments(nbTriangles*3); for (PxU32 i=0; i<nbTriangles; i++) { PxVec3 wp[3]; getTriangle(*this, i, wp, transformed, indices, has16BitIndices()); const PxU32 localMaterialIndex = getTriangleMaterialIndex(i); scolor = colors[localMaterialIndex % colorCount]; segments[0] = PxDebugLine(wp[0], wp[1], scolor); segments[1] = PxDebugLine(wp[1], wp[2], scolor); segments[2] = PxDebugLine(wp[2], wp[0], scolor); segments+=3; } PX_FREE(transformed); } if ((mask & (PxU64(1) << PxVisualizationParameter::eCOLLISION_EDGES)) && mExtraTrigData) visualizeActiveEdges(out, *this, nbTriangles, NULL, absPose, midt); } }
void SampleVehicleSceneQueryData::free() { PX_FREE(this); }
//FIXME: add LOCALFUNC? (OR GLOBAL?) BYTE* RECURSIVE_SUBROUTINE(BYTE t, list *cur_guess, list *guesses, list_node *first_guess) { if ( t == key_length) { unsigned char* key=NULL; // generate key from the cur_guess (push guesses into a matrix and use some matrix solving library?) MAT* A; VEC *x,*b; PERM* pivot; A=m_get(key_length,key_length); b=v_get(key_length); x=v_get(key_length); int c=0,r=0; for(list_node* iter=list_head(cur_guess); iter != NULL && r<key_length; iter=list_node_next(iter)){ for(c=list_node_data_ptr(iter,byte_sum_guess_t)->i1; c <= list_node_data_ptr(iter,byte_sum_guess_t)->i2; ++c){ A->me[r][c]=1; } b->ve[r]=list_node_data_ptr(iter,byte_sum_guess_t)->value; ++r; } //Calculate matrix determinant SQRMATRIX A_det; SQRMATRIX_CreateMatrix(&A_det,key_length); for(r=0;r<key_length;++r){ for(c=0;c<key_length;++c){ A_det.array[r][c]=A->me[r][c]; } } int det; det=SQRMATRIX_CalcDeterminant(&A_det); //TODO: return this later SQRMATRIX_DestroyMatrix(&A_det); if(det==0){//If determinant is 0 continue to next guess ++count_bad_matrix; #ifdef __DEBUG //SQRMATRIX_DisplayMatrix(&A_det); v_output(b); #endif DEBUG_PRINT("Matrix determinant is 0\n"); }else{ ++count_guesses; pivot = px_get(A->m); LUfactor(A,pivot); x=LUsolve(A,pivot,b,VNULL); PX_FREE(pivot); //test key (use our RC4 impl) key=(unsigned char*)malloc(sizeof(unsigned char)*key_length); for(int i=0;i<key_length;++i){ key[i]=x->ve[i]; } int res=rc4_test_key(key); if(res){ printf("MAZAL TOV! we got the right key.\n"); print_key(key); printf("\n"); }else{ printf("Tried key: "); print_key(key); printf("\n"); free(key);key=NULL; } } //release matrix vars M_FREE(A); V_FREE(x); V_FREE(b); return key; } byte_sum_guess_t cur; //list *new_list_head=guesses; //TODO: (later) add a for loop running along the "lambeda_t" values here, for the initial impl we'll try the best guess //for () //{ for(int i=0; i<LAMBDA_T; ++i){ cur = *(list_node_data_ptr(first_guess, byte_sum_guess_t)); list_node *biatch = list_add_head(cur_guess, &cur); BYTE* res=RECURSIVE_SUBROUTINE(t+1, cur_guess, guesses, list_node_next(first_guess)); if(res!=NULL){ return res; } list_del(cur_guess,biatch); first_guess = list_node_next(first_guess); } return NULL; //TODO: do something to find the next guess and link it to the current guess //when I say something I mean find best guess (i.e best weight) of all the guesses that give us new information //(i.e not linearily dependent in our byte values and sums matrix that can be deduced from the cur_guess) //see also the note above (intuition) //IMPORTANT! //explaination how cur_guess is a matrix: each entry in cur_guess contains a list of bytes that are part of the sum and a //guess as to the value of the sum. if this matrix is solvable then solving it should give us a value for each byte of the //key thus the entire key //note: we probably should change cur_guess to a smarter database (for example a (L)x(L+1) matrix as an array?) but we //need to consider that we need to keep the ability to backtrack without making it too expensive //TODO: if weight of the guess is too small -> return FAIL (section 4.6) //These are based on section 4.4 //correct suggestions (this can be done later, basic alg should work without it) //adjust weights (this can be done later, basic alg should work without it) //merge counters (section 4.2), also skip for initial impl? need to check //go to next iteration in the recurtion //RECURSIVE_SUBROUTINE(t+1, cur_guess, ); //} end of for }
ReadWriteLock::~ReadWriteLock() { mImpl->~ReadWriteLockImpl(); PX_FREE( mImpl ); }
MemoryMappedFile::~MemoryMappedFile(void) { PX_FREE(mImpl); }
void PxVehicleDrivableSurfaceToTireFrictionPairs::release() { PX_FREE(this); }