SpiderPig Posted January 29, 2023 Share Posted January 29, 2023 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? Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted January 29, 2023 Author Share Posted January 29, 2023 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; } Quote Link to comment Share on other sites More sharing options...
Josh Posted January 29, 2023 Share Posted January 29, 2023 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. 1 1 Quote 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 More sharing options...
SpiderPig Posted January 29, 2023 Author Share Posted January 29, 2023 I will, thanks. What did you set the minimum too? Does newton define a minimum or is it a bug on their end you think? Quote Link to comment Share on other sites More sharing options...
Josh Posted January 29, 2023 Share Posted January 29, 2023 I set both to 0.01. I've brought this up with Julio before and his response was basically "don't do that". 1 Quote 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 More sharing options...
SpiderPig Posted January 29, 2023 Author Share Posted January 29, 2023 I'll have to re-think a few things then. Some of the triangles with marching cubes can be a quite small. Quote Link to comment Share on other sites More sharing options...
Josh Posted January 29, 2023 Share Posted January 29, 2023 If they are that small they will not contribute to collision anyways, so don't worry about it. I'll have an update later today. 1 Quote 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 More sharing options...
SpiderPig Posted January 29, 2023 Author Share Posted January 29, 2023 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. Quote Link to comment Share on other sites More sharing options...
Josh Posted January 29, 2023 Share Posted January 29, 2023 If you can reliably produce the error please give me some code to run. Quote 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 More sharing options...
SpiderPig Posted January 29, 2023 Author Share Posted January 29, 2023 I updated the example in my second post. I'm using a triangle that was crashing in my other project. It's still pretty small but it is a visible triangle. I think the edge lengths of this triangle is 0.03 and 0.017. Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted January 31, 2023 Author Share Posted January 31, 2023 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); } Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted January 31, 2023 Author Share Posted January 31, 2023 As well as the crash in newton I get a crash here sometimes too. Don't know what's causing it, it happens in conjunction with the newton crash. Quote Link to comment Share on other sites More sharing options...
Josh Posted January 31, 2023 Share Posted January 31, 2023 An update is available now which fixes this. Let me know if you see any other problems. Quote 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 More sharing options...
SpiderPig Posted January 31, 2023 Author Share Posted January 31, 2023 I'm downloading it now. Do you mean you perfected the triangle size test for CreateCollsionMesh()? Quote Link to comment Share on other sites More sharing options...
Josh Posted January 31, 2023 Share Posted January 31, 2023 I don't know if it's perfect, but your example no longer causes any problem. 1 Quote 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 More sharing options...
SpiderPig Posted January 31, 2023 Author Share Posted January 31, 2023 My example is working now but I still get crashes in my voxel terrain project. There must be something else going on. Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted January 31, 2023 Author Share Posted January 31, 2023 Are we able to debug newton ourselves? Is that possible? Quote Link to comment Share on other sites More sharing options...
Josh Posted January 31, 2023 Share Posted January 31, 2023 It is. If you download the last versiion of Newton 3.14 on Github you can compile a DLL and run your app to debug the DLL. 1 Quote 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 More sharing options...
SpiderPig Posted January 31, 2023 Author Share Posted January 31, 2023 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? 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 Quote Link to comment Share on other sites More sharing options...
Josh Posted February 1, 2023 Share Posted February 1, 2023 I have uploaded my build of Newton 3 here: https://github.com/UltraEngine/NewtonDynamics3 It would probably be better for me to debug your project. I don't think you will get any useful information out of the Newton debug output. 1 Quote 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 More sharing options...
SpiderPig Posted February 1, 2023 Author Share Posted February 1, 2023 Thanks that worked. You are correct. Although it gives me an idea on what's going on it doesn't help me much. But it is cool to see it break to the physics code and at least tell me something. Your welcome to remote debug if you wish. Quote Link to comment Share on other sites More sharing options...
Josh Posted February 1, 2023 Share Posted February 1, 2023 I need the code anyways, so might as well send me the project. Quote 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 More sharing options...
SpiderPig Posted February 1, 2023 Author Share Posted February 1, 2023 Okay, I will collect everything into a smaller project for you tomorrow evening. Quote Link to comment Share on other sites More sharing options...
Solution Josh Posted February 2, 2023 Solution Share Posted February 2, 2023 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. 1 Quote 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 More sharing options...
SpiderPig Posted February 2, 2023 Author Share Posted February 2, 2023 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.