   Weird Bug (feels like code is not being executed))
  Hi Guys, hopefully you can help.I have been working with PhysX and Directx.After initalising PhysX i get an object's PhysX matrix, convert it to directX, manipulate it and then apply it to the PhysX object, to rotate and translate, i.e. set a starting point.I do it like this:   D3DXMATRIX matT;NxMat34 Tmat;trike->getGlobalPose().getColumnMajor44(matT);matT = Rotate(0,90,0)*Translate(0,0,-10)*matT;Tmat.setColumnMajor44(matT);trike->setGlobalPose(Tmat);This code is at the end of this function:void InitNx(){// Initialize Camera Parameters//gCameraAspectRatio= 1.0f;//gCameraPos= NxVec3(0, 5, -15);//gCameraForward= NxVec3(0,0,1);//gCameraRight= NxVec3(-1,0,0);// Create a memory allocator    if (!gAllocator){gAllocator = new UserAllocator;assert(gAllocator);}// Create the physics SDK    gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, gAllocator);if (gPhysicsSDK) {// connect to PVD, then you can see the physics objects inside PVD (you should start PVD before your application)gPhysicsSDK->getFoundationSDK().getRemoteDebugger()->connect("localhost", 5425);}    if(!gPhysicsSDK){MessageBox(NULL, L"PhysX Could Not be Initalised. This could be due to it not being installed", L"PhysX Error", MB_OK);ShellExecute(NULL, L"open", L"http://www.nvidia.com/object/physx_system_software.html",NULL, NULL, SW_SHOWNORMAL);}// Set the physics parametersgPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.01);    NxSceneDesc sceneDesc;    sceneDesc.gravity= gDefaultGravity;    sceneDesc.simType= NX_SIMULATION_SW;    gScene = gPhysicsSDK->createScene(sceneDesc);    // Create the default material   gSelectedActor = trike;NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0);defaultMaterial->setRestitution(0.5);    defaultMaterial->setStaticFriction(0.5);    defaultMaterial->setDynamicFriction(0.5);    // Create the objects in the scene///////////////////////^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^£££££££££££££££££££££££££££££££//////////////////////////////////////////////////////////////////////////////////////gTerrain = GenerateTriangleMesh(room.MMesh(), "room.bin");// Reset wheel materialwsm = NULL;// Create the trike actortrike = CreateTrike(NxVec3(-20,0,0));trike->wakeUp(1e30);AddUserDataToActors(gScene);// Get the current timedeltatime = UpdateTime();// Start the first frame of the simulationif (gScene)  {StartPhysics();}D3DXMATRIX matT;NxMat34 Tmat;//trike->getGlobalPose().getColumnMajor44(tempmatModel);trike->getGlobalPose().getColumnMajor44(matT);matT = Rotate(0,90,0)*Translate(0,0,-10)*matT;Tmat.setColumnMajor44(matT);trike->setGlobalPose(Tmat);}When running the program, the object is manipulated prefectly about 5/6 of the time. But occasionally, the matrix is not applied. I really can't work out why!Why will it work sometimes and not all or nothing. Computers should do the same thing every time.My first thought was that it might be something to do with the clean up of the program, but i don't know how i'm supposed to clean up PhysX and Directx classes, i thought they were done automatically.Just so you know i quit the program using the Escape key and the WinMain function i use is below:int WINAPI WinMain(HINSTANCE hInstance,    HINSTANCE hPrevInstance,    LPSTR lpCmdLine,    int nCmdShow){    HWND hWnd;    WNDCLASSEX wc;    ZeroMemory(&wc, sizeof(WNDCLASSEX));    wc.cbSize = sizeof(WNDCLASSEX);    wc.style = CS_HREDRAW | CS_VREDRAW;    wc.lpfnWndProc = (WNDPROC)WindowProc;    wc.hInstance = hInstance;    wc.hCursor = LoadCursor(NULL, IDC_ARROW);    wc.lpszClassName = L"DirectxGameEngine";    RegisterClassEx(&wc);    hWnd = CreateWindowEx(NULL, L"DirectxGameEngine", L"DirectxGameEngine", WS_OVERLAPPEDWINDOW, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL);    ShowWindow(hWnd, nCmdShow);    // set up and initialize Direct3D    initD3D(hWnd);InitNx();//Where the function is called from in WinMain.    // enter the main loop:    MSG msg;    while(TRUE)    {++fps;   DWORD starting_point = GetTickCount();   if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))   {  if (msg.message == WM_QUIT) break;  TranslateMessage(&msg);  DispatchMessage(&msg);   }   render_frame();   // check the 'escape' key   if(KEY_DOWN(VK_ESCAPE))  PostMessage(hWnd, WM_DESTROY, 0, 0);   while ((GetTickCount() - starting_point) < 25);    }    // clean up DirectX and COMReleaseNx();    cleanD3D();    return msg.wParam;}Any and all commments Welcome (i'm hoping this is just a noob mistake!)Any if you need anymore information just let me know!Thanks in advanceJamesCobras[Edited by - JamesCobras on June 25, 2009 8:48:28 AM]
  Have you stepped through it in the debugger?   ;Quote:Original post by MikeTacularHave you stepped through it in the debugger?Yeah i have, but after i posted the original post:I watch the matices, in the bugged game and when it is normal.The matrices are the same if bugged and if not bugged!Hmm.... now i'm really stumped....Checked the set up matrices (the directx one and PhysX one), they are the same..Will now set through and see if other matrices mess up. But why would this be an intermitent problem...The two states are always the same, i.e. when bugged the objects are always in the one place, when not bugged objects are in a another place place. So there is not any weird randomisation/heap over run or any really weird behavior, like random values.grr................Well the bug is not in the intialisation bit but else where. This problem began to occur after the inisalisation though.JamesCobras   ;  UPDATE:Found exactly where the issue lies.Its a problem with PhysXits at this function   D3DXMATRIX matT;NxMat34 Tmat;trike->getGlobalPose().getColumnMajor44(matT);matT = Rotate(0,90,0)*Translate(0,0,-10)*matT;Tmat.setColumnMajor44(matT);//here matT = Tmat in debugger, good so far!trike->setGlobalPose(Tmat);//so the matrix goes in right   trike->getGlobalPose().getColumnMajor44(testmatrix);// but when you get it again, guess what testmatrix != Tmat or matTweird, eh? I can't do much about that! That is really bad eh?Here is the debug, just incase you want to see it.This is all gathered from a break point after the above code.matT{...}D3DXMATRIX_D3DMATRIX{_11=-4.3711388e-008 _12=0.00000000 _13=-1.0000000 ...}_D3DMATRIX_11-4.3711388e-008float_120.00000000float_13-1.0000000float_140.00000000float_210.00000000float_221.0000000float_230.00000000float_240.00000000float_311.0000000float_320.00000000float_33-4.3711388e-008float_340.00000000float_41-20.000000float_421.0000000float_43-10.000000float_441.0000000floatm0x0042c5c0 struct D3DXMATRIX matTfloat [4][4]Tmat{M={...} t={...} }NxMat34M{data={...} }NxMat33data{s={...} m=0x0042c768 }Nx9Reals{_11=-4.3711388e-008 _12=0.00000000 _13=1.0000000 ...}Nx9Real::S_11-4.3711388e-008float_120.00000000float_131.0000000float_210.00000000float_221.0000000float_230.00000000float_31-1.0000000float_320.00000000float_33-4.3711388e-008floatm0x0042c768 class NxMat34 Tmatfloat [3][3]t{x=-20.000000 y=1.0000000 z=-10.000000 }NxVec3x-20.000000floaty1.0000000floatz-10.000000floattestmatrix{...}D3DXMATRIX_D3DMATRIX{_11=1.0000000 _12=0.00000000 _13=0.00000000 ...}_D3DMATRIX_111.0000000float_120.00000000float_130.00000000float_140.00000000float_210.00000000float_221.0000000float_230.00000000float_240.00000000float_310.00000000float_320.00000000float_331.0000000float_340.00000000float_41-20.000000float_421.0000000float_430.00000000float //note no -10 here!!!!!_441.0000000floatm0x0042c618 struct D3DXMATRIX testmatrixfloat [4][4]Any ideas which might help me fix this?JamesCobras   