Forcing Chipmunk to use floats

Official forum for the Chipmunk2D Physics Library.
Post Reply
Latexi95
Posts: 6
Joined: Sat Sep 24, 2011 3:36 pm
Contact:

Forcing Chipmunk to use floats

Post by Latexi95 »

Is there any way to force Chipmunk to use floats instead of doubles? If I define CP_USE_DOUBLES to 0 in chipmunk_types.h Visual Studio 2010 gives me these kind of warning:

Code: Select all

Warning	40	warning C4789: destination of memory copy is too small	chipmunk-6.0.2\src\cpspace.c	line 129
and if I try to create body application will crash. Everything works fine when I don't define CP_USE_DOUBLES.

Btw, I would be nice, if Chipmunk's bodies had some kind of "bullet mode" (Box2D's bodies have), so they could go thought wall's when moving fast or timestep is high. :)

Sorry bad english.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Forcing Chipmunk to use floats

Post by slembcke »

Setting CP_USE_DOUBLES to 0 should work. Maybe I messed something up somewhere though. I worked fine a couple months ago when I did some performance testing, and on the iPhone. Do you really want to use floats instead of doubles on a desktop CPU? Even on an Atom processor, doubles will make the computations faster as the CPU needs to convert them to doubles while loading them into registers. Chipmunk doesn't use a lot of memory bandwidth so you don't have to worry about the extra size slowing you down.

Did you modify cpSpace.c? Line 129 is:

Code: Select all

	cpBodyInitStatic(&space->_staticBody);
I don't see why that would make the warning that it does.

Swept or "bullet" collisions are very expensive to perform. There's a reason why Chipmunk runs 3x faster than Box2D. ;)
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Latexi95
Posts: 6
Joined: Sat Sep 24, 2011 3:36 pm
Contact:

Re: Forcing Chipmunk to use floats

Post by Latexi95 »

Thank you for the answer.

I didn't know that doubles work faster than floats. Coolbasic (programming language what for I'm doing this library) always uses floats, so I have to convert doubles to floats. :oops:

"CP_USE_DOUBLES 0" doesn't seem to work. I haven't changed that line. Warning has something to do with "CP_USE_DOUBLES 0" because it doesn't show up if I don't define it. But I think, I won't use floats... :lol:

Again one "BTW" question: Any idea how this is made?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Forcing Chipmunk to use floats

Post by slembcke »

Hmm. Well I'll look into that when I get the time. It should work.

SPH == Smoothed Particle Hydrodynamics. This is a good paper on the subject:
http://citeseerx.ist.psu.edu/viewdoc/do ... 1&type=pdf
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Latexi95
Posts: 6
Joined: Sat Sep 24, 2011 3:36 pm
Contact:

Re: Forcing Chipmunk to use floats

Post by Latexi95 »

Thank you.

Problem might be in my code, because it is quite hard to debug dll, when you can't use debugger... :roll:
I try to create crash again in fully c++ application. I will post if I found the problem.
Latexi95
Posts: 6
Joined: Sat Sep 24, 2011 3:36 pm
Contact:

Re: Forcing Chipmunk to use floats

Post by Latexi95 »

This goes even stranger... I tried "Hello Chipmunk" example.
If I compile it in release mode, it will work fine. But If I build in debug mode, "Access violation" will happen in body.c in cpBodyAddShape

Code: Select all

cpBodyAddShape(cpBody *body, cpShape *shape)
{
	cpShape *next = body->shapeList;
	if(next) next->prev = shape;   // <<<<----- here
	
	shape->next = next;
	body->shapeList = shape;
}
and program print to console:

Code: Select all

Aborting due to Chipmunk error: This shape is already added to a space and canno
t be added to another.
        Failed condition: !shape->space
[/size]

But if I add line

Code: Select all

#define CP_USE_DOUBLES 0
before including chipmunk.h and I build in debug mode, program will work correctly.
And If I then (with "CP_USE_DOUBLES 0") build it in release mode, "Access violation" will happen at line

Code: Select all

cpShapeSetFriction(ground, 1);
I'm using VS2010 and I downloaded latest Chipmunk release and I built it using vs2010 solution file.

Edit: Okey... I think, I somehow built using old library version or something...
Now without "CP_USE_DOUBLES 0" debug mode works fine. But "CP_USE_DOUBLES 0" and release build mode combination still crashes.

Edit2: If I remove static "ground" body, program doesn't crash, but ballBody's position won't change (it's (-1.#J,0.0) ) and vertical velocity is very high (-0.00, 160801377226902880000000000000000000000.00).
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests