martyj Posted December 4, 2017 Share Posted December 4, 2017 In Leadwerks 4.4 when running Model::Copy on an entity several times the game will crash. The code: World* world = World::GetCurrent(); if (world->terrain == NULL) { return; } std::map<std::string, std::string> vegNameEntMap = { { "fallowdeer", "Deer" }, }; int vegCount = world->terrain->CountVegetationLayers(); for (int i = 0; i < vegCount; i++) { VegetationLayer* layer = world->terrain->GetVegetationLayer(i); std::string modelPath = layer->modelpath; std::string parentName = ""; System::Print(modelPath); for (auto it = vegNameEntMap.begin(); it != vegNameEntMap.end(); it++) { if (modelPath.find(it->first) != std::string::npos) { parentName = it->second; break; } } if (parentName.size() == 0) { continue; } // Hide Layer layer->viewrange = 0; Entity* model = world->FindEntity(parentName); if (model == NULL) { continue; } Vec3 scale = model->GetScale(); AABB aabb = world->aabb; std::vector<Mat4> instances; layer->GetInstancesInAABB(aabb, instances); System::Print("Loading Layer: " + parentName + " of Size: " + std::to_string(instances.size())); for (unsigned int j = 0; j < instances.size(); j++) { Mat4 instance = instances[j]; Entity* copy = model->Copy(true, false); copy->SetMatrix(instance, true); copy->SetScale(scale); } } The program seems to consistently crash around 1.7 GB of RAM used. If I replace the code in the loop with this it also crashes: Entity* copy = Model::Load(modelPath); copy->SetMatrix(instance, true); copy->SetScale(scale); You can download my project here: (200Mb) (Removed) I plan to use this code for having wild animals roam my land. Using the vegetation system to place different interactable entities such as Trees or Animals. Quote Link to comment Share on other sites More sharing options...
Josh Posted December 4, 2017 Share Posted December 4, 2017 Several? ?. From looking at your code it is likely you are running out of memory. Use Instance() instead of Copy(). The latter will make a new copy of all the mesh data. Also understand the vegetation system can create millions of instances...which is why it is designed to not store anything in memory. guess what would happen if I decided I wanted an infinite terrain system? We already have an infinite vegetation system. ? 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...
martyj Posted December 4, 2017 Author Share Posted December 4, 2017 Ah very well could be hitting the memory limit. I didn't think of the process as being 32 bit only having access to 2.3 Gb of ram. I'll try Instance instead. So as far as the vegetation system goes, for these items I'm only using the vegetation system for layout. Instead of manually copying an entity all over my map, I'll use the easy vegetation system to layout my entities. I'm running a 1024x1024 terrain size. Quote Link to comment Share on other sites More sharing options...
martyj Posted December 5, 2017 Author Share Posted December 5, 2017 So switching from Copy to Instance only lets me load about 10% more. I think I need to implement a vegetation type system for these animals as no matter what, it will be using a ton of memory. Thanks for the help! Quote Link to comment Share on other sites More sharing options...
Josh Posted December 5, 2017 Share Posted December 5, 2017 How many entities are we talking? 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...
martyj Posted December 5, 2017 Author Share Posted December 5, 2017 600 using model->Instance(true, false); on the demo project in my link. Quote Link to comment Share on other sites More sharing options...
Josh Posted December 5, 2017 Share Posted December 5, 2017 I think that is a reasonable number of animated characters, especially when you consider how many limbs there are there. 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...
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.