diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-08-18 16:08:24 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-08-18 16:08:24 (GMT) |
| commit | 7018e46fac29ba41398dc49b069aa9aeaa37b04d (patch) | |
| tree | 45c0b98be36e7f1a1accb03b423a34837b2cbf03 /src/simulation/Simulation.cpp | |
| parent | 69b788ba7d7c0910369cbff0f708c949195683bc (diff) | |
| download | powder-7018e46fac29ba41398dc49b069aa9aeaa37b04d.zip powder-7018e46fac29ba41398dc49b069aa9aeaa37b04d.tar.gz | |
Remove disabled elements when simulating. Fix crash when kill_part is run on elements with invalid types
Diffstat (limited to 'src/simulation/Simulation.cpp')
| -rw-r--r-- | src/simulation/Simulation.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 1eb7ed9..ebc0fed 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -2477,7 +2477,7 @@ void Simulation::kill_part(int i)//kills particle number i if (parts[i].type == PT_NONE) return; - if(elementCount[parts[i].type] && parts[i].type) + if(parts[i].type > 0 && parts[i].type < PT_NUM && elementCount[parts[i].type] && parts[i].type) elementCount[parts[i].type]--; if (parts[i].type == PT_STKM) { @@ -3352,7 +3352,7 @@ void Simulation::update_particles_i(int start, int inc) if (parts[i].type) { t = parts[i].type; - if (t<0 || t>=PT_NUM) + if (t<0 || t>=PT_NUM || !elements[i].Enabled) { kill_part(i); continue; @@ -4588,11 +4588,14 @@ Simulation::Simulation(): memcpy(platent, platentT, latentCount * sizeof(unsigned int)); free(platentT); - elements = new Element[PT_NUM]; + //elements = new Element[PT_NUM]; std::vector<Element> elementList = GetElements(); - for(int i = 0; i < elementList.size(); i++) + for(int i = 0; i < PT_NUM; i++) { - elements[i] = elementList[i]; + if(i < elementList.size()) + elements[i] = elementList[i]; + else + elements[i] = Element_NONE(); } tools = GetTools(); |
