CPUParticles initialize data on set_amount

Fills particle data with zeroes on resize using set_amount(), to prevent garbage data including Nans being sent to VisualServer, which can corrupt the spatial partitioning.
This commit is contained in:
lawnjelly 2022-09-19 16:53:01 +01:00 committed by Relintai
parent 4da6c31ba9
commit cd68b6e1e2
2 changed files with 15 additions and 1 deletions

View File

@ -63,6 +63,13 @@ void CPUParticles2D::set_amount(int p_amount) {
}
particle_data.resize((8 + 4 + 1) * p_amount);
// We must fill immediately to prevent garbage data and Nans
// being sent to the visual server with set_as_bulk_array,
// if this is sent before being regularly updated.
particle_data.fill(0);
particle_data_prev.fill(0);
RS::get_singleton()->multimesh_allocate(multimesh, p_amount, RS::MULTIMESH_TRANSFORM_2D, RS::MULTIMESH_COLOR_8BIT, RS::MULTIMESH_CUSTOM_DATA_FLOAT);
particle_order.resize(p_amount);

View File

@ -88,7 +88,14 @@ void CPUParticles::set_amount(int p_amount) {
particle_data.resize((12 + 4 + 1) * p_amount);
particle_data_prev.resize(particle_data.size());
RS::get_singleton()->multimesh_allocate(multimesh, p_amount, RS::MULTIMESH_TRANSFORM_3D, RS::MULTIMESH_COLOR_8BIT, RS::MULTIMESH_CUSTOM_DATA_FLOAT);
// We must fill immediately to prevent garbage data and Nans
// being sent to the visual server with set_as_bulk_array,
// if this is sent before being regularly updated.
particle_data.fill(0);
particle_data_prev.fill(0);
RS::get_singleton()->multimesh_allocate(multimesh, p_amount, RS::MULTIMESH_TRANSFORM_2D, RS::MULTIMESH_COLOR_8BIT, RS::MULTIMESH_CUSTOM_DATA_FLOAT);
particle_order.resize(p_amount);
}