Fix crash on startup on emscripten

Parts::data was never initialized, and this mattered on emscripten, even though it didn't matter anywhere else.
This commit is contained in:
Tamás Bálint Misius
2025-01-24 01:19:24 +01:00
parent ea93bae302
commit cb65cf8ffd
2 changed files with 16 additions and 2 deletions

View File

@@ -976,6 +976,12 @@ int Simulation::parts_avg(int ci, int ni,int t)
return PT_NONE;
}
void Parts::Reset()
{
memset(data.data(), 0, sizeof(Particle)*NPART);
lastActiveIndex = 0;
}
void Simulation::clear_sim(void)
{
for (auto i = 0; i <= parts.lastActiveIndex; i++)
@@ -994,13 +1000,12 @@ void Simulation::clear_sim(void)
signs.clear();
memset(bmap, 0, sizeof(bmap));
memset(emap, 0, sizeof(emap));
memset(parts, 0, sizeof(Particle)*NPART);
parts.Reset();
for (int i = 0; i < NPART-1; i++)
parts[i].life = i+1;
parts[NPART-1].life = -1;
pfree = 0;
NUM_PARTS = 0;
parts.lastActiveIndex = 0;
memset(pmap, 0, sizeof(pmap));
memset(fvx, 0, sizeof(fvx));
memset(fvy, 0, sizeof(fvy));

View File

@@ -50,12 +50,21 @@ struct Parts
return data.data();
}
Parts()
{
Reset();
}
Parts(const Parts &other) = default;
Parts &operator =(const Parts &other)
{
std::copy(other.data.begin(), other.data.begin() + other.lastActiveIndex + 1, data.begin());
lastActiveIndex = other.lastActiveIndex;
return *this;
}
void Reset();
};
struct RenderableSimulation