Jump to content

Newton Crash


SpiderPig
 Share

Go to solution Solved by Josh,

Recommended Posts

I've not been able to reproduce this problem in a smaller program yet.  I thinks it's happening because I am using CreateMeshCollider().  Sometimes I'm creating single triangles and others are collection of 2 or 3, all with non-shared vertices.  I'm trying to figure out how to narrow down the problem and thought there might be a direct answer to a few questions in the process -

  • Does newton not like really small triangles?
  • OR vertices that are at the same position or really close?
  • Is it meant to work with flat planes (or single triangles) or does it like volume collisions like cube colliders?

NewtonCrash.thumb.png.d82c85e5294b2a87c62932892c1ae119.png

Link to comment
Share on other sites

Well I think it's understandable why this code crashes.  The second vertex is too close to the first or it makes the triangle to small for newton to handle or something.  @Josh should CreateMeshCollider() this have a some sort of safety check maybe?

#include "UltraEngine.h"
#include "ComponentSystem.h"

using namespace UltraEngine;

int main(int argc, const char* argv[])
{
    auto displays = GetDisplays();
    auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
    auto world = CreateWorld();
    auto framebuffer = CreateFramebuffer(window);

    auto camera = CreateCamera(world);
    camera->SetClearColor(0.125);
    camera->SetFov(70);
    camera->SetPosition(0, 0, -10);

    auto light = CreateDirectionalLight(world);
    light->SetColor(5.0f);
    light->SetRotation(35, 45, 0);

    vector<shared_ptr<Entity>> entities;
    vector<shared_ptr<Entity>> pivots;
    Vec3 emitter_position = Vec3(0.0f, 10.0f, 0.0f);
    float emitter_size = 5.0f;
    uint64_t start = Millisecs(), interaval = 250;



    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        auto time = Millisecs();
        if (time > start + interaval) {
            start = time;

            float x, y, z;
            x = emitter_position.x + Random(-emitter_size, emitter_size);
            y = emitter_position.y + emitter_size;
            z = emitter_position.z + Random(-emitter_size, emitter_size);

            auto e = CreateBox(world);
            e->SetPosition(x, y, z);
            e->SetColor(Random(), Random(), Random());
            e->SetMass(1.0f);

            entities.push_back(e);

            //Create collision object
            auto mesh = CreateMesh();
            mesh->AddVertex(29.0, 3.97082719, 25.0);
            mesh->AddVertex(29.0, 4.0, 25.0178719);
            mesh->AddVertex(29.0397224, 4.0, 25.0);
            mesh->AddPrimitive(0, 1, 2);

            auto pivot = CreatePivot(world);
            auto collider = CreateMeshCollider(mesh);

            pivot->SetCollider(collider);
            pivot->SetCollisionType(COLLISION_SCENE);
            pivots.push_back(pivot);
        }

        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

 

Link to comment
Share on other sites

I added a check for minimum triangle area and edge lengths. I dislike the fact that this is not exact. Please let me know if you encounter this again after today's update.

  • Thanks 1
  • Upvote 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

My example above still crashes.  I have also seen it crash on something a little larger too.  When I find it again I'll test it in the above program.  Seeing as it's not an accurate test maybe there should just be a warning in the documentation and make users aware of it?  If anything I think Newton should have a check for it on their end.

Link to comment
Share on other sites

I've been trying to solve this.  While this code does seem stop small triangles being created I still will get a crash sooner rather than later.  So who knows.  Maybe my code isn't flawless.

void CollisionPatch::AddTriangle(int a, int b, int c) {
	Vec3 min = { FLT_MAX, FLT_MAX, FLT_MAX }, max = { FLT_MIN, FLT_MIN, FLT_MIN };
	int i[3] = { a,b,c };
	for (auto id = 0; id < 3; id++) {
		min.x = Min(min.x, vertices[i[id]].position.x);
		min.y = Min(min.y, vertices[i[id]].position.y);
		min.z = Min(min.z, vertices[i[id]].position.z);

		max.x = Max(max.x, vertices[i[id]].position.x);
		max.y = Max(max.y, vertices[i[id]].position.y);
		max.z = Max(max.z, vertices[i[id]].position.z);
	}

	auto threshold = 0.5f;
	auto dx = max.x - min.x;
	auto dy = max.y - min.y;
	auto dz = max.z - min.z;

	auto count = 0;
	if (dx < threshold) { count++; }
	if (dy < threshold) { count++; }
	if (dz < threshold) { count++; }

	if (count > 1) {
		return;
	}
	
	indices.emplace_back(a);
	indices.emplace_back(b);
	indices.emplace_back(c);
}

 

Link to comment
Share on other sites

I think I've compile the right one "newton-dynamics-master\newton-3.14\sdk\projects\visualStudio_2015_dll", I copied the "newton_d.dll" that was generated into my project and it crashes.  Nothing is ever easy.  I also tried replacing "dCustomJoints_d.dll" but it gave a similar error.  Perhaps some things have changed?

NewtonError.png.8ded45a0ad8bbbf4b8b87844d9f9a7d3.png

The DLL is also about 2mb bigger than the one shipped with Ultra.  Anyway it's here if you like to try it for yourself.  I don't know how I'm going to pinpoint theses errors without debugging newton but we will see.

newton_d.zip

Link to comment
Share on other sites

  • Solution

I can't say what the problem was but I clean and rebuild of the engine fixed it. The update is available now on 1.0.1.

BTW, it seems a lot of your colliders consist of 1-2 triangles. This is probably very inefficient and it would be better if they were in bigger pieces, but that should still not cause a crash like you were experiencing.

  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Thanks its all working now.

26 minutes ago, Josh said:

BTW, it seems a lot of your colliders consist of 1-2 triangles. This is probably very inefficient and it would be better if they were in bigger pieces, but that should still not cause a crash like you were experiencing.

They do and I was actually wondering if it would be better to make less colliders with more triangles each so I will do this.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...