]> sigrok.org Git - pulseview.git/commitdiff
Analog buffer sharing crash by memcpying for the AnanlogSignal::paint
authorJoel Holdsworth <redacted>
Fri, 15 Mar 2013 18:28:28 +0000 (18:28 +0000)
committerJoel Holdsworth <redacted>
Thu, 21 Mar 2013 22:44:18 +0000 (22:44 +0000)
pv/data/analogsnapshot.cpp
pv/data/analogsnapshot.h
pv/view/analogsignal.cpp

index 2bcb99f3e978c47903d22d58b8a54482eb227b4a..1658a04c3bfe365138b5ba21f064702e3719e0f7 100644 (file)
@@ -49,9 +49,21 @@ void AnalogSnapshot::append_payload(
        append_data(analog.data, analog.num_samples);
 }
 
-const float* AnalogSnapshot::get_samples() const
+const float* AnalogSnapshot::get_samples(
+       int64_t start_sample, int64_t end_sample) const
 {
-       return (const float*)_data;
+       assert(start_sample >= 0);
+       assert(start_sample < (int64_t)_sample_count);
+       assert(end_sample >= 0);
+       assert(end_sample < (int64_t)_sample_count);
+       assert(start_sample <= end_sample);
+
+       lock_guard<recursive_mutex> lock(_mutex);
+
+       float *const data = new float[end_sample - start_sample];
+       memcpy(data, (float*)_data + start_sample, sizeof(float) *
+               (end_sample - start_sample));
+       return data;
 }
 
 } // namespace data
index 9ca08f1e510d3d564bd5367c180a336edc2ae630..a45391849220332b892faa9ed3eaa79df30a4df6 100644 (file)
@@ -36,7 +36,8 @@ public:
 
        void append_payload(const sr_datafeed_analog &analog);
 
-       const float* get_samples() const;
+       const float* get_samples(int64_t start_sample,
+               int64_t end_sample) const;
 };
 
 } // namespace data
index 209512b595880d9be9e55aed4947935e89b5ae22..a6f032b5793aa0422e8e71b07f5e5b2f56fb3e2d 100644 (file)
@@ -68,18 +68,21 @@ void AnalogSignal::paint(QPainter &p, int y, int left, int right, double scale,
                (int64_t)0), last_sample);
        const int64_t end_sample = min(max((int64_t)ceil(end),
                (int64_t)0), last_sample);
+       const int64_t sample_count = end_sample - start_sample;
 
-       const float* samples = snapshot->get_samples();
+       const float* samples = snapshot->get_samples(
+               start_sample, end_sample);
        assert(samples);
 
-       QPointF *points = new QPointF[end_sample - start_sample];
+       QPointF *points = new QPointF[sample_count];
        QPointF *point = points;
 
        for (int64_t sample = start_sample;
                sample != end_sample; sample++) {
                const float x = (sample / samples_per_pixel -
                        pixels_offset) + left;
-               *point++ = QPointF(x, samples[sample] + y);
+               *point++ = QPointF(x,
+                       samples[sample - start_sample] + y);
        }
 
        p.setPen(_colour);