mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps/shared] Prevent label method from being called on uninitialized chars
This commit is contained in:
committed by
EmilieNumworks
parent
5b106f091d
commit
990c45b661
@@ -190,6 +190,8 @@ int CurveView::numberOfLabels(Axis axis) const {
|
||||
float minLabel = std::ceil(min(axis)/labelStep);
|
||||
float maxLabel = std::floor(max(axis)/labelStep);
|
||||
int numberOfLabels = maxLabel - minLabel + 1;
|
||||
// Assert labels are up to date
|
||||
assert(m_drawnRangeVersion == m_curveViewRange->rangeChecksum());
|
||||
assert(numberOfLabels <= (axis == Axis::Horizontal ? k_maxNumberOfXLabels : k_maxNumberOfYLabels));
|
||||
return numberOfLabels;
|
||||
}
|
||||
@@ -226,19 +228,24 @@ void CurveView::computeLabels(Axis axis) {
|
||||
|
||||
if (axis == Axis::Horizontal) {
|
||||
if (labelBuffer[0] == 0) {
|
||||
/* Some labels are too big and may overlap their neighbours. We write the
|
||||
/* Some labels are too big and may overlap their neighbors. We write the
|
||||
* extrema labels only. */
|
||||
computeHorizontalExtremaLabels();
|
||||
return;
|
||||
break;
|
||||
}
|
||||
if (i > 0 && strcmp(labelBuffer, label(axis, i-1)) == 0) {
|
||||
/* We need to increase the number if significant digits, otherwise some
|
||||
* labels are rounded to the same value. */
|
||||
computeHorizontalExtremaLabels(true);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
int maxNumberOfLabels = (axis == Axis::Horizontal ? k_maxNumberOfXLabels : k_maxNumberOfYLabels);
|
||||
// All remaining labels are empty. They shouldn't be accessed anyway.
|
||||
for (int i = axisLabelsCount; i < maxNumberOfLabels; i++) {
|
||||
label(axis, i)[0] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void CurveView::simpleDrawBothAxesLabels(KDContext * ctx, KDRect rect) const {
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
namespace Shared {
|
||||
|
||||
uint32_t CurveViewRange::rangeChecksum() {
|
||||
float data[4] = {xMin(), xMax(), yMin(), yMax()};
|
||||
size_t dataLengthInBytes = 4*sizeof(float);
|
||||
float data[7] = {xMin(), xMax(), yMin(), yMax(), xGridUnit(), yGridUnit(), offscreenYAxis()};
|
||||
size_t dataLengthInBytes = 7*sizeof(float);
|
||||
assert((dataLengthInBytes & 0x3) == 0); // Assert that dataLengthInBytes is a multiple of 4
|
||||
return Ion::crc32Word((uint32_t *)data, dataLengthInBytes/sizeof(uint32_t));
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
X,
|
||||
Y
|
||||
};
|
||||
virtual uint32_t rangeChecksum();
|
||||
uint32_t rangeChecksum();
|
||||
|
||||
virtual float xMin() const = 0;
|
||||
virtual float xMax() const = 0;
|
||||
|
||||
@@ -19,13 +19,6 @@ void InteractiveCurveViewRange::setDelegate(InteractiveCurveViewRangeDelegate *
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t InteractiveCurveViewRange::rangeChecksum() {
|
||||
float data[] = {xMin(), xMax(), yMin(), yMax()};
|
||||
size_t dataLengthInBytes = sizeof(data);
|
||||
assert((dataLengthInBytes & 0x3) == 0); // Assert that dataLengthInBytes is a multiple of 4
|
||||
return Ion::crc32Word((uint32_t *)data, dataLengthInBytes/sizeof(uint32_t));
|
||||
}
|
||||
|
||||
void InteractiveCurveViewRange::setZoomAuto(bool v) {
|
||||
if (m_zoomAuto == v) {
|
||||
return;
|
||||
|
||||
@@ -29,7 +29,6 @@ public:
|
||||
bool isOrthonormal() const;
|
||||
|
||||
void setDelegate(InteractiveCurveViewRangeDelegate * delegate);
|
||||
uint32_t rangeChecksum() override;
|
||||
|
||||
bool zoomAuto() const { return m_zoomAuto; }
|
||||
void setZoomAuto(bool v);
|
||||
|
||||
Reference in New Issue
Block a user