Havok Vehicle creation

Havok Vehicle creation

Hi,

I try to add vehicle to my code and I can't do it. I took most from the demo VehicleApiDemo and I can compile it but it gives me an error.

I took most from it without createDisplayWheels, camera, steering. I wanted to just see the vehicle in the debugger first.

In debug build mode I get error "Unhandled exception at 0x0110a476 in HavokOGL_1.exe: 0xC0000005: Access violation reading location 0x0000002c. The program '[7740] HavokOGL_1.exe: Native' has exited with code -1073741819 (0xc0000005)."

And it points me to the file hkMemoryRouter.h to the line 74 " inline Allocator& heap() { return *m_heap; }"

This is the code I added to my code: http://pastebin.com/h5FSP2MB

This is my whole code: http://pastebin.com/6ttSAL67

void Pojazd() on the bottom in added code is my function, rest is mostly copied. Sorry for the big mess in code. I am not a good programmer, and I keep everything in one file.

I would be really greatfull if someone could help me identifying what I am doing wrong and how to fix it.

14 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

Hi Krisboss--

Can you provide the callstack of the crash?

With regard to clarity of code, I guarantee that if you organize your code in a more structured manner, it will help you track down these kind of errors - not to mention make it easier for others to assist you. Developing the discipline of clean code is well worth the effort!

--Tim

Hi,

Could you please explain how to see the callstack information of the crash? I don't know how to get it, all I can see in the debug info in visual studio is:

'HavokOGL_1.exe': Loaded 'D:\HavokOGL_1\HavokOGL_1\Debug\HavokOGL_1.exe', Symbols loaded.
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Program Files\AVAST Software\Avast\snxhk.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\opengl32.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\glu32.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\ddraw.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\dciman32.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\setupapi.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\devobj.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\dwmapi.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'D:\HavokOGL_1\HavokOGL_1\Debug\glut32.dll', Binary was not built with debug information.
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\winmm.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded.
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\wsock32.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\ws2_32.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\nsi.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file
'HavokOGL_1.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file
First-chance exception at 0x00e8a476 in HavokOGL_1.exe: 0xC0000005: Access violation reading location 0x0000002c.
Unhandled exception at 0x00e8a476 in HavokOGL_1.exe: 0xC0000005: Access violation reading location 0x0000002c.
The program '[4772] HavokOGL_1.exe: Native' has exited with code -1073741819 (0xc0000005).

Hi Krisboss--

The callstack window shows up in Visual Studio when debugging. After selecting "Debug > Start Debugging," look for a tab with this name. If you do not see it, you can show it by selecting Debug > Windows > Call Stack.

--Tim

Hi,

Ok, here is what is displayed in my callstack window:

> HavokOGL_1.exe!hkMemoryRouter::heap() Line 74 + 0x26 bytes C++
HavokOGL_1.exe!hkpConvexVerticesShape::operator new(unsigned int nbytes) Line 37 + 0x36 bytes C++
HavokOGL_1.exe!createCarChassisShape() Line 662 + 0x7 bytes C++
HavokOGL_1.exe!`dynamic initializer for 'chassisShape''() Line 681 + 0x23 bytes C++
msvcr100d.dll!_initterm(void (void)* * pfbegin, void (void)* * pfend) Line 873 C
HavokOGL_1.exe!__tmainCRTStartup() Line 473 + 0xf bytes C
HavokOGL_1.exe!mainCRTStartup() Line 371 C
kernel32.dll!759233aa()
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
ntdll.dll!773e9ef2()
ntdll.dll!773e9ec5()

Hi KrissBoss--

The problem appears to be that you're trying to create Havok data at static initialization before the Havok memory system has been initialized. In particular, you'lre calling createCarChassisShape() to initialize the global variable chassisShape. You should wait to call this function until after you have called OnInit(). Please let me know if you need any further clarification - thanks. 

--Tim

Hi,

I think you were right about that createCarChassisShape(). I moved it inside my Pojazd(); function but I get other problems that give me breakpoint.

When I comment this two functions the program works:

m_vehicle->addToWorld( m_world );

m_world->addAction(m_vehicle);

I can even see the chassis shape in the visual debugger falling on the ground. But without this functions it's probably just a shape not a vehicle.

Here is my callstack report after the changes with those two functions uncommented:

HavokOGL_1.exe!hkpWorld::addEntity(hkpEntity * entity, hkpEntityActivation initialActivationState) Line 834 + 0x72 bytes C++
HavokOGL_1.exe!hkpVehicleInstance::addToWorld(hkpWorld * world) Line 1083 C++
> HavokOGL_1.exe!Pojazd() Line 720 + 0x1b bytes C++
HavokOGL_1.exe!OnInit() Line 1289 C++
HavokOGL_1.exe!main(int argc, char * * argv) Line 1544 C++
HavokOGL_1.exe!__tmainCRTStartup() Line 555 + 0x19 bytes C
HavokOGL_1.exe!mainCRTStartup() Line 371 C
kernel32.dll!75f333aa()
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
ntdll.dll!76f79ef2()
ntdll.dll!76f79ec5()

Hi Krissboss--

If you check your console output window you should see an error message that reads "You are trying to add an entity to the world which has already been added to a world." Try stepping through the code in the debugger to figure out how this is happening.

--Tim

Hi,

I wasn't having much time latelty and that's why I wasn't responding here or trying to fix my code. But now I tried to do it and found out what was the problem. I found that I was creating chassisbody with wronge method that was commented in the demo code and later was creating it again. I must have uncommented it by mistake. That really shows what you said that if I would keep my code clean and organized that kind of errors would be esier to find and less occuring. 

So now I have the car instance working, I drew it in openGL as a box and I have the steering working too. I wanted to add simple follow camera but the rotation that I take from the car with function "chassisRigidBody->getRotation()" is from 0 to 180 degrees because it depends on the axis too, so is there a way to take rotation in form from 0 to 360 degrees? Because the follow cam in havok looks strange and I wanted to implement my own whic is easier looking.

My follow camera looks like this

gluLookAt(vehicleX+cos(vehicleRotation*3.14/180)*-7, vehicleY+3, vehicleZ+sin(vehicleRotation*3.14/180)*-7, vehicleX, vehicleY, vehicleZ,0.0f, 1.0f, 0.0f);

Hi Krissboss--

An hkQuaternion represents a rotation as a combination of an axis of rotation and an angle around this axis. The range of the angle goes from 0 to 180 degrees because the other 180 degrees are represented by flipping the axis of rotation to point in the opposite direction.

The best way to get the ey direction you need for gluLookAt is to rotate the canonical eye direction by the hkQuaternion. Let hkVector4 canonicalEye be the default eye direction with a rotation of zero (say the unit-z vector). You can then calculate the eye direction with something like this:

hkVector4 eyeDirection;
eyeDirection.setRotatedDir(chassisRigidBody->getRotation(), canonicalEye);
gluLookAt(eyeDirection.getComponent<0>(), eyeDirection.getComponent<1>(), eyeDirection.getComponent<2>(), vehicleX, vehicleY, vehicleZ,0.0f, 1.0f, 0.0f);

Please let me know if you have any further questions. Thanks!

--Tim

Hi,

This really helped me and my follow camera is working great now. I'm not sure if I did everything like you said because I also added the vehicle position next to eveDirection but it's working good now.

I would also want to ask how to draw wheels. I see the createdisplaywheels function in the demo but I am not sure how to use it. Could you explain it to me? I'm not sure what I really need to draw them in OpenGL and if they are already there in the vehicle or need to be created. But the vehicle works like it's having wheels. But how to get their position and rotation for drawing?

Hi Krissboss--

You can call hkpVehicleInstance::calcCurrentPositionAndRotation() with a wheel index to get the corresponding position and rotation of each wheel. You can use this to place your own wheel graphics mesh correctly relative to your car's chassis. Please let me know if you have any furhter questions - thanks!

--Tim

Hi,

This was a great tip and I made my wheels working well and drawn each wheel where it should be. Thank you very much.

I wondered how to make manual transmission, I found this topic but could you explain it to me a bit more?

 http://software.intel.com/en-us/forums/topic/299984

and this

http://software.intel.com/pt-br/comment/1607412

what exacly does override means, and do I need to find it in the source files and copy to my code and change or what? And could you also  explain the general idea how it should be made to work good and realisticly.

Hi krisboss,

Override in c++ refers to creating a new implementation for a virtual function in a derived class.  This is a basic concept of polymorphic programming, which allows a derived class to share some but not all of the functionality of the class it inherits from.  In this case, you would create a new manual transmission class that inherits from the default automatic transmission, and you would change only the functionality that is different.  Please seek out some resources inheritance and polymorphism such as these, and make sure you understand before you proceed:

https://en.wikipedia.org/wiki/C%2B%2B#Polymorphism

http://www.cplusplus.com/doc/tutorial/inheritance/

cheers,

Josh

Josh S. Havok Developer Support Engineer www.havok.com

Laisser un commentaire

Veuillez ouvrir une session pour ajouter un commentaire. Pas encore membre ? Rejoignez-nous dès aujourd’hui