From 065edbbf057675814043ced3e6284bf7bf2f2f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 4 Sep 2019 14:23:17 +0200 Subject: [PATCH] [apps/shared] Range1D is used in a Storage::Record::DataBuffer and thus should be packed and might be unaligned --- apps/shared/range_1D.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/apps/shared/range_1D.h b/apps/shared/range_1D.h index e95d625ef..e1d63c0ed 100644 --- a/apps/shared/range_1D.h +++ b/apps/shared/range_1D.h @@ -6,7 +6,11 @@ namespace Shared { -class Range1D { +/* This class is used in a DataBuffer of a Storage::Record. See comment in + * Shared::Function::FunctionRecordDataBuffer about packing. */ + +#pragma pack(push,1) +class Range1D final { public: constexpr static float k_minFloat = 1E-4f; Range1D(float min = -10.0f, float max = 10.0f) : @@ -20,9 +24,17 @@ public: static float clipped(float x, bool isMax, float lowerMaxFloat, float upperMaxFloat); static float defaultRangeLengthFor(float position); private: +#if __EMSCRIPTEN__ + // See comment about emscripten alignement in Shared::Function::FunctionRecordDataBuffer + static_assert(sizeof(emscripten_align1_short) == sizeof(uint16_t), "emscripten_align1_short should have the same size as uint16_t"); + emscripten_align1_float m_min; + emscripten_align1_float m_max; +#else float m_min; float m_max; +#endif }; +#pragma pack(pop) static_assert(Range1D::k_minFloat >= FLT_EPSILON, "InteractiveCurveViewRange's minimal float range is lower than float precision, it might draw uglily curves such as cos(x)^2+sin(x)^2");