cant declear hkpWorldCinfo variable

cant declear hkpWorldCinfo variable


I can't init the havok physic because every time I want to declear hkpWorldCinfo I got an error like this:

First-chance exception at 0x009ad346 in FrontGame.exe: 0xC0000005: Access violation reading location 0xffffffff.

even if I declear it as global member same error happen.

I creat my physic engine this way:

m_physicEngine =new CHavokPhysic();

and my class constructor:

    // Do platform specific initialization
    // Initialize the base system including our memory system
    // Allocate 0.5MB of physics solver buffer.
    hkMemoryRouter* memoryRouter;
    memoryRouter = hkMemoryInitUtil::initDefault( hkMallocAllocator::m_defaultMallocAllocator, hkMemorySystem::FrameInfo( 500* 1024 ) );
    hkBaseSystem::init( memoryRouter, HavokerrorReport );
        // We can cap the number of threads used - here we use the maximum for whatever multithreaded platform we are running on. This variable is
        // set in the following code sections.
        int totalNumThreadsUsed;
    #if defined HK_PLATFORM_PS3_PPU
        hkSpuJobThreadPoolCinfo threadPoolCinfo;
        extern CellSpurs* initSpurs();
        HK_CELL_SPURS* spurs = initSpurs();
        hkSpuUtil* spuUtil = new hkSpuUtil( spurs );
        threadPoolCinfo.m_spuUtil = spuUtil;
        threadPoolCinfo.m_maxNumSpus = 5; // Use 5 SPUs for this example
        totalNumThreadsUsed = 1; // only use one CPU thread for PS3.
        // This line enables timers collection, by allocating 200 Kb per thread.  If you leave this at its default (0),
        // timer collection will not be enabled.
        threadPoolCinfo.m_perSpuMonitorBufferSize = 200000;
        threadPool = new hkSpuJobThreadPool( threadPoolCinfo );
        // Get the number of physical threads available on the system
        hkHardwareInfo hwInfo;
        totalNumThreadsUsed = hwInfo.m_numThreads;
        // We use one less than this for our thread pool, because we must also use this thread for our simulation
        hkCpuJobThreadPoolCinfo threadPoolCinfo;
        threadPoolCinfo.m_numThreads = totalNumThreadsUsed - 1;
        // This line enables timers collection, by allocating 200 Kb per thread.  If you leave this at its default (0),
        // timer collection will not be enabled.
        threadPoolCinfo.m_timerBufferPerThreadAllocation = 200000;
        threadPool = new hkCpuJobThreadPool( threadPoolCinfo );
        // We also need to create a Job queue. This job queue will be used by all Havok modules to run multithreaded work.
        // Here we only use it for physics.
        hkJobQueueCinfo info;
        info.m_jobQueueHwSetup.m_numCpuThreads = totalNumThreadsUsed;
        jobQueue = new hkJobQueue(info);
        // Enable monitors for this thread.
        // Monitors have been enabled for thread pool threads already (see above comment).
            // The world cinfo contains global simulation parameters, including gravity, solver settings etc.
            hkpWorldCinfo worldInfo;//got the error here!!!
            // Set the simulation type of the world to multi-threaded.
            worldInfo.m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_MULTITHREADED;
            // Flag objects that fall "out of the world" to be automatically removed - just necessary for this physics scene
            //worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_REMOVE_ENTITY;
            physicsWorld = new hkpWorld(worldInfo);
            // Disable deactivation, so that you can view timers in the VDB. This should not be done in your game.
            //physicsWorld->m_wantDeactivation = false;
            // When the simulation type is SIMULATION_TYPE_MULTITHREADED, in the debug build, the sdk performs checks
            // to make sure only one thread is modifying the world at once to prevent multithreaded bugs. Each thread
            // must call markForRead / markForWrite before it modifies the world to enable these checks.
            // Register all collision agents, even though only box - box will be used in this particular example.
            // It's important to register collision agents before adding any entities to the world.
            hkpAgentRegisterUtil::registerAllAgents( physicsWorld->getCollisionDispatcher() );
            // We need to register all modules we will be running multi-threaded with the job queue
            physicsWorld->registerWithJobQueue( jobQueue );
            // Create all the physics rigid bodies
            //setupPhysics( physicsWorld );
            // The visual debugger so we can connect remotely to the simulation
            // The context must exist beyond the use of the VDB instance, and you can make
            // whatever contexts you like for your own viewer types.
            context = new hkpPhysicsContext();
            hkpPhysicsContext::registerAllPhysicsProcesses(); // all the physics viewers
            context->addWorld(physicsWorld); // add the physics world so the viewers can see it
            // Now we have finished modifying the world, release our write marker.
        vdb = new hkVisualDebugger(contexts);
        // Contexts are not reference counted at the base class level by the VDB as
        // they are just interfaces really. So only delete the context after you have
        // finished using the VDB.
        delete jobQueue;
        // Clean up the thread pool
    #if defined HK_PLATFORM_PS3_PPU
        extern void quitSpurs( CellSpurs* spurs );
        quitSpurs( spurs );

5 posts / novo 0
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.

Hi Hamed E.--

I do not believe your error is actually coming from the line you marked since the hkpWorldCinfo struct does not dereference any pointers. My guess is that the error actually comes from the previous line, but your callstack is getting mangled. Try placing a breakpoint on that line or add some intermediate printfs to double check. Let me know how that goes.


I manage to solve this problem.But it seems this class use special memory alignment.Because when I declare it as global variable it break the heap but I can declare it on the stack as local variable.So I almost sure there is a memory alignment code in this class and it should be 16 bit alignment because I cant use it as global variable.

Hi Hamed E.--

Is it an instance of CHavokPhysic that you are declaring as either global or local, or the hkpWorldCinfo? In any case, declaring as a local vs. global should not change the alignment characteristics. It seems more likely that this is a static initialization problem of some kind. Havok requires that the memory system be fully initialized before any other Havok systems, which could also contribute to your issue.

In any case, it sounds like you have a workaround, but if you want to send on further information, we can look into it more thoroughly.


CHavokPhysic is global.I can't declare hkpWorldCinfo as global but I can use it as local variable

Deixar um comentário

Faça login para adicionar um comentário. Não é membro? Inscreva-se hoje mesmo!