zonciu / box2dsharp Goto Github PK
View Code? Open in Web Editor NEWA C# port of Box2D
License: MIT License
A C# port of Box2D
License: MIT License
新建了一个winform工程测试了下Box2DSharp。
关闭窗体退出程序就会报这个错:
System.ObjectDisposedException
HResult=0x80131622
Message=无法访问已释放的对象。
ObjectDisposed_ObjectName_Name
Source=mscorlib
StackTrace:
在 System.Threading.ThreadLocal1.GetValueSlow() 在 System.Threading.ThreadLocal
1.get_Value()
在 System.Collections.Concurrent.ConcurrentBag1.GetThreadList(Boolean forceCreate) 在 System.Collections.Concurrent.ConcurrentBag
1.Add(T item)
在 Box2DSharp.Common.SimpleObjectPool1.Return(IEnumerable
1 items) 在 D:\Pro2019\Box2DSharpPlay\Box2DSharp\Common\ObjectPool.cs 中: 第 88 行
在 Box2DSharp.Collision.DynamicTree.Dispose() 在 D:\Pro2019\Box2DSharpPlay\Box2DSharp\Collision\DynamicTree.cs 中: 第 69 行
在 Box2DSharp.Collision.DynamicTree.Finalize() 在 D:\Pro2019\Box2DSharpPlay\Box2DSharp\Collision\DynamicTree.cs 中: 第 56 行
======================
代码就new 了一个World,添加了几个body,什么都没做。
退出前手动world.Dispose()也不行。
When I set gravity(Y) in world.Gravity/gravityScale for a body to a big value(40-50 gravityScale for example) I get my CPU 100% loaded. In the same time, I can create a lot of bodies with gravityScale<40 I get my processor works fine, as without these bodies at all.
Hi,
Is the Unity project really working/done? Apparently is using dependencies of ImGUI and several others, I can't compile.
Regards.
Hello,
I have this set-up running using Box2DSharp:
var World = new World(new Vector2(0, -10));
var groundShape = new ChainShape();
groundShape.CreateLoop(new[]
{
new Vector2(-5, 0),
new Vector2(5, 0),
new Vector2(5, 5),
new Vector2(4, 1),
new Vector2(-4, 1),
new Vector2(-5, 5)
});
var groundFixtureDef = new FixtureDef
{
Density = 0,
Shape = groundShape
};
var groundBodyDef = new BodyDef
{
BodyType = BodyType.StaticBody
};
var groundBody = World.CreateBody(groundBodyDef);
groundBody.CreateFixture(groundFixtureDef);
var ballShape = new CircleShape { Radius = 1 };
var ballFixtureDef = new FixtureDef
{
Density = 1,
Restitution = 0.75f,
Shape = ballShape
};
var ballBodyDef = new BodyDef
{
BodyType = BodyType.DynamicBody,
Position = new Vector2(0, 10)
};
var ball = World.CreateBody(ballBodyDef);
ball.CreateFixture(ballFixtureDef);
ball.ApplyForceToCenter(new Vector2(-1000, -400), true);
and this one, an identical one running Box2D:
b2Vec2 gravity;
gravity.Set(0.0f, -10.0f);
m_world = new b2World(gravity);
b2ChainShape chainShape;
b2Vec2 vertices[] = {b2Vec2(-5,0), b2Vec2(5,0), b2Vec2(5,5), b2Vec2(4,1), b2Vec2(-4,1), b2Vec2(-5,5)};
chainShape.CreateLoop(vertices, 6);
b2FixtureDef groundFixtureDef;
groundFixtureDef.density = 0;
groundFixtureDef.shape = &chainShape;
b2BodyDef groundBodyDef;
groundBodyDef.type = b2_dynamicBody;
b2Body *groundBody = m_world->CreateBody(&groundBodyDef);
b2Fixture *groundBodyFixture = groundBody->CreateFixture(&groundFixtureDef);
b2CircleShape ballShape;
ballShape.m_radius = 1;
b2FixtureDef ballFixtureDef;
ballFixtureDef.restitution = 0.75f;
ballFixtureDef.density = 1;
ballFixtureDef.shape = &ballShape;
b2BodyDef ballBodyDef;
ballBodyDef.type = b2BodyType::b2_dynamicBody;
ballBodyDef.position = b2Vec2(0, 10);
b2Body *ball = m_world->CreateBody(&ballBodyDef);
b2Fixture *ballFixture = ball->CreateFixture(&ballFixtureDef);
ball->ApplyForceToCenter(b2Vec2(-1000, -400), true);
I also made sure that both b2Settings were set the same.
As you might notice the original Box2D seems to be quicker at damping the force of the ball, my guess is that this might have something to do with the friction calculation or maybe a rounding issue. In this example, the original Box2D ball stops right away, while on Box2DSharp, the ball keeps on going even after colliding against the ball and then until it collides the other wall, but it takes a really long time for it to move, but makes it there. So the results are very different.
Any ideas of what could be causing this?
现在有个想法是世界暂停后持久化/序列化,将来再恢复。希望加上这个feature。
我看到有Dump方法声明了,什么时候继续?
优化对象回收到对象池的逻辑,发现问题请在此处留言。
分支:dev
Hi,
I noticed that you use the in keyword when passing down a Vector2. I think you might be doing this for performance reasons to avoid copying the Vector2. However, Vector2 is not a readonly struct, so when you do this, I believe the compiler is making defensive copies of Vector2 regardless, making this not efficient.
https://github.com/Zonciu/Box2DSharp/blob/master/src/Common/MathUtils.cs#L12
More about in
arguments with mutable structures:
https://docs.microsoft.com/en-us/dotnet/csharp/write-safe-efficient-code#avoid-mutable-structs-as-an-in-argument
打开unity测试工程后提示 edgeshape类不包含set函数。
04-25 11:27:08.624 32136 5338 I IL2CPP : Fail:
04-25 11:27:08.624 32136 5338 I IL2CPP : tactListener listener) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.624 32136 5338 I IL2CPP : at Box2DSharp.Dynamics.ContactManager.Collide () <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.624 32136 5338 I IL2CPP : at Box2DSharp.Dynamics.World.Step (System.Single timeStep, System.Int32 velocityIterations, System.Int32 positionIterations) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.624 32136 5338 I IL2CPP : at DJ.WorldComponentSystem.WorldLogic (DJ.WorldComponent self, System.Single delayTime) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.624 32136 5338 I IL2CPP : at ET.EventSystem.FixedUpdate () <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.624 32136 5338 I IL2CPP : ics.Fixture fixture, Box2DSharp.Dynamics.Contacts.Contact contact) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.624 32136 5338 I IL2CPP : at DJ.CollisionListenerComponent.BeginContact (Box2DSharp.Dynamics.Contacts.Contact contact) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.624 32136 5338 I IL2CPP : at Box2DSharp.Dynamics.Contacts.Contact.Update (Box2DSharp.Dynam
04-25 11:27:08.625 32136 5338 I IL2CPP : at System.Diagnostics.DefaultTraceListener.Fail (System.String message, System.String detailMessage) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at System.Diagnostics.TraceInternal.Fail (System.String message) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at Box2DSharp.Collision.DynamicTree.RayCast (Box2DSharp.Dynamics.Internal.ITreeRayCastCallback& inputCallback, Box2DSharp.Collision.Collider.RayCastInput& input) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at Box2DSharp.Dynamics.World.RayCast (Box2DSharp.Dynamics.IRayCastCallback& callback, System.Numerics.Vector2& point1, System.Numerics.Vector2& point2) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at DJ.Tools.CheckMaskRay (System.Object obj, Box2DSharp.Dynamics.World world, System.UInt16 layerMask, System.Numerics.Vector2 start, System.Numerics.Vector2 end, DJ.ParamsRayCast paramsRayCast, System.Boolean debug) <0x00000 + 0xffffffff> 0 in <00000000000000000000000
04-25 11:27:08.625 32136 5338 I IL2CPP : 00000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at DJ.ColliderHelp.WithDesUnitHasBlock (DJ.ColliderComponent self, System.Numerics.Vector2 desPos, System.Boolean& hasBlock, System.UInt16 layerMask) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at DJ.BulletTypeStaticEffect.HitUnit (DJ.Unit eUnit) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at DJ.BulletHelper.CollectHitDes (DJ.BulletComponent self, DJ.ColliderComponent entity, System.Boolean hasDestroyItem) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at DJ.ColliderComponentSystem.CollisionStartEdge (DJ.ColliderComponent self, DJ.ColliderComponent entity, Box2DSharp.Dynamics.Fixture fixture, Box2DSharp.Dynamics.Contacts.Contact contact) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at DJ.CollisionListenerComponent.BeginContact (Box2DSharp.Dynamics.Contacts.Contact contact) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at Box2DSharp.Dynamics.Contacts.Contact.Update (Box2DSharp.Dynam
04-25 11:27:08.625 32136 5338 I IL2CPP : cs.IContactListener listener) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at Box2DSharp.Dynamics.ContactManager.Collide () <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at Box2DSharp.Dynamics.World.Step (System.Single timeStep, System.Int32 velocityIterations, System.Int32 positionIterations) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at DJ.WorldComponentSystem.WorldLogic (DJ.WorldComponent self, System.Single delayTime) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at ET.EventSystem.FixedUpdate () <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : ics.Fixture fixture, Box2DSharp.Dynamics.Contacts.Contact contact) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at DJ.CollisionListenerComponent.BeginContact (Box2DSharp.Dynamics.Contacts.Contact contact) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0
04-25 11:27:08.625 32136 5338 I IL2CPP : at Box2DSharp.Dynamics.Contacts.Contact.Update (Box2DSharp.Dynam
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.