diff options
| author | jacob1 <jfu614@gmail.com> | 2013-09-12 18:35:10 (GMT) |
|---|---|---|
| committer | jacob1 <jfu614@gmail.com> | 2013-09-12 18:35:10 (GMT) |
| commit | aa2ec3d1624bb4dd88b276d8ada6aae8073571fc (patch) | |
| tree | e44ed8634d7dcba0ae41ca515736ec54c0198bf0 /src/simulation | |
| parent | 074a2226e168b4860e0e19ff50956752cdb51a77 (diff) | |
| download | powder-aa2ec3d1624bb4dd88b276d8ada6aae8073571fc.zip powder-aa2ec3d1624bb4dd88b276d8ada6aae8073571fc.tar.gz | |
fix SOAP crashes by making sure particle id's are between 0 and NPART. Also cut off .life to between 0 and 65535 when saving
Diffstat (limited to 'src/simulation')
| -rw-r--r-- | src/simulation/elements/SOAP.cpp | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/simulation/elements/SOAP.cpp b/src/simulation/elements/SOAP.cpp index fb88287..2e721d1 100644 --- a/src/simulation/elements/SOAP.cpp +++ b/src/simulation/elements/SOAP.cpp @@ -161,7 +161,6 @@ int Element_SOAP::update(UPDATE_FUNC_ARGS) } else if (parts[r>>8].ctype == 7 && parts[i].tmp != r>>8 && parts[i].tmp2 != r>>8) { - int buf; parts[parts[i].tmp].tmp2 = parts[r>>8].tmp2; parts[parts[r>>8].tmp2].tmp = parts[i].tmp; parts[r>>8].tmp2 = i; @@ -181,17 +180,20 @@ int Element_SOAP::update(UPDATE_FUNC_ARGS) parts[i].vx += dx*d; parts[i].vy += dy*d; if ((parts[parts[i].tmp].ctype&2) && (parts[parts[i].tmp].ctype&1) + && (parts[parts[i].tmp].tmp >= 0 && parts[parts[i].tmp].tmp < NPART) && (parts[parts[parts[i].tmp].tmp].ctype&2) && (parts[parts[parts[i].tmp].tmp].ctype&1)) { - int ii; - ii = parts[parts[parts[i].tmp].tmp].tmp; - dx = parts[ii].x - parts[parts[i].tmp].x; - dy = parts[ii].y - parts[parts[i].tmp].y; - d = 81/(pow(dx, 2)+pow(dy, 2)+81)-0.5; - parts[parts[i].tmp].vx -= dx*d*0.5f; - parts[parts[i].tmp].vy -= dy*d*0.5f; - parts[ii].vx += dx*d*0.5f; - parts[ii].vy += dy*d*0.5f; + int ii = parts[parts[parts[i].tmp].tmp].tmp; + if (ii >= 0 && ii < NPART) + { + dx = parts[ii].x - parts[parts[i].tmp].x; + dy = parts[ii].y - parts[parts[i].tmp].y; + d = 81/(pow(dx, 2)+pow(dy, 2)+81)-0.5; + parts[parts[i].tmp].vx -= dx*d*0.5f; + parts[parts[i].tmp].vy -= dy*d*0.5f; + parts[ii].vx += dx*d*0.5f; + parts[ii].vy += dy*d*0.5f; + } } } } |
