Forráskód Böngészése

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.
lawnjelly 3 éve
szülő
commit
fdd82f4754
2 módosított fájl, 12 hozzáadás és 0 törlés
  1. 5 0
      scene/2d/cpu_particles_2d.cpp
  2. 7 0
      scene/3d/cpu_particles.cpp

+ 5 - 0
scene/2d/cpu_particles_2d.cpp

@@ -62,6 +62,11 @@ 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);
+
 	VS::get_singleton()->multimesh_allocate(multimesh, p_amount, VS::MULTIMESH_TRANSFORM_2D, VS::MULTIMESH_COLOR_8BIT, VS::MULTIMESH_CUSTOM_DATA_FLOAT);
 
 	particle_order.resize(p_amount);

+ 7 - 0
scene/3d/cpu_particles.cpp

@@ -85,6 +85,13 @@ void CPUParticles::set_amount(int p_amount) {
 
 	particle_data.resize((12 + 4 + 1) * p_amount);
 	particle_data_prev.resize(particle_data.size());
+
+	// 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);
+
 	VS::get_singleton()->multimesh_allocate(multimesh, p_amount, VS::MULTIMESH_TRANSFORM_3D, VS::MULTIMESH_COLOR_8BIT, VS::MULTIMESH_CUSTOM_DATA_FLOAT);
 
 	particle_order.resize(p_amount);