FractureCollisionListener Linking Problem

FractureCollisionListener Linking Problem

Hi,

I am converting the simple game example in order to create a destruction game for a university project.

I want to create a fracturable box and I am trying to initialize a GlassFractureCollisionListener. I use the code the way I found it in the demos:

hkArray m_fracturedBodies;
class FractureCollisionListener* m_collisionListener;

m_collisionListener = new GlassFractureCollisionListener( &m_fracturedBodies, 5.0f );

When I try to run the project I get the error below:

game.obj : error LNK2019: unresolved external symbol "public: __thiscall GlassFractureCollisionListener::GlassFractureCollisionListener(class hkArray *,float)" (??0GlassFractureCollisionListener@@QAE@PAV?$hkArray@PAVhkpRigidBody@@UhkContainerHeapAllocator@@@@M@Z) referenced in function "void __cdecl OnInit(void)" (?OnInit@@YAXXZ)
1>bin\\GCP_SimpleGame_d.exe : fatal error LNK1120: 1 unresolved externals

I tried to add some of the related files to my project (GlassFractureCollisionListener.h, GlassFractureCollisionListener.cpp) but after that I got new linking errors.

What are the required steps in order to use the FractureUtil (or any other relevant Havok feature) in an project?

Thank you.

10 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Best Reply

Hello ernesto505,

The error you are getting is due to the fact that the GlassFractureCollisionListener class you are using is defined in the "Demos\DemoCommon" folder which has not been built in any of our .lib files so you will need to compile the relevant .cpp files yourself if you want to use it in your own project. There are no "required" steps per say in order to use the FractureUtil in your own solution because these Utilities have been deliberately designed for our demos project only.
Here are two methods however that will help you solve your issue (I assume that you are using Visual Studio but the methods should work in any other IDE as well):

1) Add all the .h/.cpp files that are needed to properly define GlassFractureCollisionListener and that are in the "Demos\DemoCommon" folder (All the other files needed should be defined in the Havok .libs which you should have listed in Project->Properties->Linker->Input->Additional Dependencies) in your game project solution.
Here is a list of the files if you only need the GlassFractureCollisionListener from the DemoCommon folder:
- All the files in the "Demo\Demos\DemoCommon\Utilities\GameUtils\Fracture" folder
- "Demo\Demos\DemoCommon\Utilities\hkGeometrySplitter.h/.cpp"

2) Create a static library with all the files listed in 1) and others if want to use more functionalities from the Demos\DemoCommon folder (You can create a Static Library Project using Visual Studio where you should not forget to include the path to the Havok source code you are trying to compile in C/C++->General->Additional Include Directories and the same Havok related Preprocessor definitions that your game project solution uses in C/C++->Preprocessor->Preprocessor Definitions (for more information on how to set up a static library project, see http://msdn.microsoft.com/en-us/library/ms235627%28v=vs.80%29.aspx)). You can then reference the output .lib file in your actual game project (by listing it in your game's project solution Project->Properties->Linker->Input->Additional Dependencies). Note that this method is cleaner and makes it easier to re-use the functionalities that you need from the Demos\DemoCommon folder in another project of yours.

Please let me know if this helps in fixing your issue,

Cheers,
David.

David G.
Developer Support Engineer
Havok
www.havok.com

Hello David,

Thank you very much for the detailed answered. I tried the first method (which was quicker) and it worked. I will now try the second one which probably will work too.

Thank you for your help.

Hello again,

After having succesfully setup a FractureCollision Listener, I am now trying to setup a BreakOffPartsUtil and I am getting another linking error.

error LNK2019: unresolved external symbol "public: __thiscall BreakOffParts::BreakOffParts(void)" (??0BreakOffParts@@QAE@XZ) referenced in function "void __cdecl OnInit(void)" (?OnInit@@YAXXZ)
1>bin\GCP_SimpleGame_d.exe : fatal error LNK1120: 1 unresolved externals

I added hkpBreakOffPartsUtil.h and hkpBreakOffPartsUtil.inl in my project but I still get the same error. I tried to find which other files I may have to include but nothing worked.

Which files are required in order to succesfully setup a BreakOffPartsUtil? Is there anything else that I may be missing?

Thank you.

Hey ernesto505-The linker is looking for BreakOffParts() defined in the class or namespace BreakOffParts. Looking through the util, though, I cannot find any function or class or namespace with just the "BreakOffParts" name.You will probably need to read through the BreakOffPartsUtil header file to see what functions are available, and to read through the demo to see how the demo uses the Util.-Josh

Josh
Developer Support Engineer
Havok
www.havok.com

Hello,

Unfortunately my last question was deleted probably due to the update.

What I said in my last post was that I managed to fix the problem with the linking error. I wasn't setting up my class correctly. After careful examination of the BreakoffPartsUtil file and the BreakoffPartsDemo I managed to fix it.

Now I have a new problem. Although I copied the process and all the required functions from BreakoffPartsDemo when I run the simulation, at the point where my object has to break I get a access violation error. I can see through Visual Debugger that the object with all the required components is there which means that my MOPP shape is created correctly. In addition I can see in debug mode that the breakOffSubPart function isn't called at all when there is a collision.

Any tips regarding what might go wrong will be really helpful. Is it possible that I can't use BreakoffUtil outside the demo framework?

Thank you

Hello ernesto505,

I have tried setting up the BreakOffPartsDemo outside the Demo Framework and it seems to work as expected: the breakOffSubPart function is being called whenever there is a collision.

Have you created a custom class that derives from hkpBreakOffPartsListener, overwrites the "breakOffSubPart(const ContactImpulseLimitBreachedEvent& event, hkArray& keysBrokenOffOut, hkpPhysicsSystem& systemOut );" function and which has an hkpBreakOffPartsUtil ( that you created using "hkpBreakOffPartsUtil( MyBreakOffPartsListenerObject );" and registered to your hkpWorld using "addWorldExtension( MyBreakOffPartsUtilObject );" ) ?

Also, could you let me know on which line you are getting the "Access Violation" error (possibly the call-stack as well)? The only possible Error I could see is in the "removeSubShapeFromDisplay" function when it is looking for the graphical representation of the sub-shape to remove from the display. Are you planning to use Havok's Graphics Engine or will you use another one? You might not be initializing m_env correctly in your code which could cause your application to crash.

Please let me know if you are still having any issues with running your simulator,

Cheers,
David.

David G.
Developer Support Engineer
Havok
www.havok.com

Hello ernesto505,

I have tried setting up the BreakOffPartsDemo outside the Demo Framework and it seems to work as expected: the breakOffSubPart function is being called whenever there is a collision.

Have you created a custom class that derives from hkpBreakOffPartsListener, overwrites the "breakOffSubPart(const ContactImpulseLimitBreachedEvent& event, hkArray& keysBrokenOffOut, hkpPhysicsSystem& systemOut );" function and which has an hkpBreakOffPartsUtil ( that you created using "hkpBreakOffPartsUtil( MyBreakOffPartsListenerObject );" and registered to your hkpWorld using "addWorldExtension( MyBreakOffPartsUtilObject );" ) ?

Also, could you let me know on which line you are getting the "Access Violation" error (possibly the call-stack as well)? The only possible Error I could see is in the "removeSubShapeFromDisplay" function when it is looking for the graphical representation of the sub-shape to remove from the display. Are you planning to use Havok's Graphics Engine or will you use another one? You might not be initializing m_env correctly in your code which could cause your application to crash.

Please let me know if you are still having any issues with running your simulator,

Cheers,
David.

David G.
Developer Support Engineer
Havok
www.havok.com

Hello David.

That is exactly what I did. Here is my class

class BreakOffParts : public hkpBreakOffPartsListener
{
public:
BreakOffParts();
~BreakOffParts();
virtual hkResult breakOffSubPart( const ContactImpulseLimitBreachedEvent& event, hkArray& keysBrokenOffOut, hkpPhysicsSystem& systemOut );
virtual hkResult breakOffSubPart( const ContactImpulseLimitBreachedEvent& event, hkpPhysicsSystem& bodiesOut ) { return HK_FAILURE; }

hkpBreakOffPartsUtil* m_breakUtil;
void createCity();
};

The constructor of the class creates hkpWorld and registers breakOffUtil using addWorldExtension as you described. Then I call the constructor in my initialization function.

I don't have any removeSubShapeFromDisplay function because as I understood from the demos this is used in relation with Havok's Graphics Engine and I use OpenGL to render my scene. The problem is that breakOffSubPart isn't called at all when I have a collision. The program breaks before that.

Here is the error I get:

First-chance exception at 0x00428fa0 in GCP_SimpleGame_d.exe: 0xC0000005: Access violation.

and the call stack I think is:

GCP_SimpleGame_d.exe!hkpSimulation::integrate(float physicsDeltaTime) Line 136 + 0x75 bytes C++

Thank you very much for your help.

Hello ernesto505,

Your code seems to be crashing when you are calling stepDeltaTime on your hkpWorld, is that right? As I cannot say for certain what causes your Access Violation, what I would suggest is determining which lines of code causes it to crash:

If you don't add a hkpBreakOffPartsUtil as a WorldExtension does it still crash?

If it is, then the crash might not be due to the BreakOffUtil so try removing/commenting more and more sections of your code until it doesn't crash anymore: Can you then determine why it doesn't crash by looking at the code you removed/commented?

If not then are you sure your hkpBreakOffPartsUtil is still valid when the collision happens?

Please let me know of your results,

David.

David G.
Developer Support Engineer
Havok
www.havok.com

Leave a Comment

Please sign in to add a comment. Not a member? Join today