[Bf-blender-cvs] [0de90d6f882] functions: make sure event data is not overwritten by later events

Jacques Lucke noreply at git.blender.org
Mon Jul 1 15:36:54 CEST 2019


Commit: 0de90d6f8821091f097c59699ab36b528fdda01f
Author: Jacques Lucke
Date:   Mon Jul 1 14:01:06 2019 +0200
Branches: functions
https://developer.blender.org/rB0de90d6f8821091f097c59699ab36b528fdda01f

make sure event data is not overwritten by later events

===================================================================

M	source/blender/simulations/bparticles/core.cpp
M	source/blender/simulations/bparticles/core.hpp
M	source/blender/simulations/bparticles/simulate.cpp

===================================================================

diff --git a/source/blender/simulations/bparticles/core.cpp b/source/blender/simulations/bparticles/core.cpp
index e6609f863bf..1d3fd648271 100644
--- a/source/blender/simulations/bparticles/core.cpp
+++ b/source/blender/simulations/bparticles/core.cpp
@@ -310,6 +310,7 @@ EventFilterInterface::EventFilterInterface(ParticleSet particles,
                                            AttributeArrays &attribute_offsets,
                                            ArrayRef<float> durations,
                                            float end_time,
+                                           ArrayRef<float> known_min_time_factors,
                                            EventStorage &r_event_storage,
                                            SmallVector<uint> &r_filtered_indices,
                                            SmallVector<float> &r_filtered_time_factors)
@@ -317,6 +318,7 @@ EventFilterInterface::EventFilterInterface(ParticleSet particles,
       m_attribute_offsets(attribute_offsets),
       m_durations(durations),
       m_end_time(end_time),
+      m_known_min_time_factors(known_min_time_factors),
       m_event_storage(r_event_storage),
       m_filtered_indices(r_filtered_indices),
       m_filtered_time_factors(r_filtered_time_factors)
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index 9e74e11016e..ac6e913de64 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -464,16 +464,21 @@ class EventFilterInterface {
   AttributeArrays &m_attribute_offsets;
   ArrayRef<float> m_durations;
   float m_end_time;
+  ArrayRef<float> m_known_min_time_factors;
 
   EventStorage &m_event_storage;
   SmallVector<uint> &m_filtered_indices;
   SmallVector<float> &m_filtered_time_factors;
 
+  /* Size can be increased when necessary. */
+  char m_dummy_event_storage[64];
+
  public:
   EventFilterInterface(ParticleSet particles,
                        AttributeArrays &attribute_offsets,
                        ArrayRef<float> durations,
                        float end_time,
+                       ArrayRef<float> known_min_time_factors,
                        EventStorage &r_event_storage,
                        SmallVector<uint> &r_filtered_indices,
                        SmallVector<float> &r_filtered_time_factors);
@@ -510,8 +515,9 @@ class EventFilterInterface {
   void trigger_particle(uint index, float time_factor);
 
   /**
-   * Same as above but returns a pointer to a struct that can be used to pass data to the execute
-   * function.
+   * Same as above but returns a reference to a struct that can be used to pass data to the execute
+   * function. The reference might point to a dummy buffer when the time_factor is after a known
+   * other event.
    */
   template<typename T> T &trigger_particle(uint index, float time_factor);
 };
@@ -822,15 +828,23 @@ inline float EventFilterInterface::end_time()
 
 inline void EventFilterInterface::trigger_particle(uint index, float time_factor)
 {
-  m_filtered_indices.append(index);
-  m_filtered_time_factors.append(time_factor);
+  if (time_factor <= m_known_min_time_factors[index]) {
+    m_filtered_indices.append(index);
+    m_filtered_time_factors.append(time_factor);
+  }
 }
 
 template<typename T>
 inline T &EventFilterInterface::trigger_particle(uint index, float time_factor)
 {
-  this->trigger_particle(index, time_factor);
-  return m_event_storage.get<T>(m_particles.get_particle_index(index));
+  BLI_assert(sizeof(T) <= sizeof(m_dummy_event_storage));
+  if (time_factor <= m_known_min_time_factors[index]) {
+    this->trigger_particle(index, time_factor);
+    return m_event_storage.get<T>(m_particles.get_particle_index(index));
+  }
+  else {
+    return *(T *)m_dummy_event_storage;
+  }
 }
 
 /* EventExecuteInterface inline functions
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index bdf032c0d10..3ad36b23d75 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -55,13 +55,12 @@ BLI_NOINLINE static void find_next_event_per_particle(ParticleSet particles,
     SmallVector<uint> triggered_indices;
     SmallVector<float> triggered_time_factors;
 
-    /* TODO: make sure that one event does not override the storage of another,
-     * if it comes later. */
     Event *event = events[event_index];
     EventFilterInterface interface(particles,
                                    attribute_offsets,
                                    durations,
                                    end_time,
+                                   r_time_factors_to_next_event,
                                    r_event_storage,
                                    triggered_indices,
                                    triggered_time_factors);
@@ -70,10 +69,10 @@ BLI_NOINLINE static void find_next_event_per_particle(ParticleSet particles,
     for (uint i = 0; i < triggered_indices.size(); i++) {
       uint index = triggered_indices[i];
       float time_factor = triggered_time_factors[i];
-      if (time_factor < r_time_factors_to_next_event[index]) {
-        r_next_event_indices[index] = event_index;
-        r_time_factors_to_next_event[index] = time_factor;
-      }
+      BLI_assert(time_factor <= r_time_factors_to_next_event[index]);
+
+      r_next_event_indices[index] = event_index;
+      r_time_factors_to_next_event[index] = time_factor;
     }
   }



More information about the Bf-blender-cvs mailing list