Skip to content

Commit

Permalink
fix: segfault with multichannel custom series hoffstadt#2307
Browse files Browse the repository at this point in the history
  • Loading branch information
jschmer committed Jun 16, 2024
1 parent 6541ac7 commit a6858d1
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/mvPlotting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2305,15 +2305,27 @@ DearPyGui::set_required_configuration(PyObject* inDict, mvCustomSeriesConfig& ou
if (!VerifyRequiredArguments(GetParsers()[GetEntityCommand(mvAppItemType::mvCustomSeries)], inDict))
return;

// required dataset for x (channel 1)
(*outConfig.value)[0] = ToDoubleVect(PyTuple_GetItem(inDict, 0));
// required dataset for y (channel 2)
(*outConfig.value)[1] = ToDoubleVect(PyTuple_GetItem(inDict, 1));
// number of channels (datasets)
outConfig.channelCount = ToInt(PyTuple_GetItem(inDict, 2));

for (int i = 0; i < outConfig.channelCount; i++)
{
outConfig._transformedValues.push_back({});
outConfig._transformedValues.back().resize((*outConfig.value)[i].size());
memcpy(outConfig._transformedValues.back().data(), (*outConfig.value)[i].data(), sizeof(double) * (*outConfig.value)[i].size());
// The plotter function DearPyGui::draw_custom_series() expects that there
// are vectors in _transformedValues present that are of the same element size
// than the x dataset (first vector in outConfig.value). This applies to all
// y datasets (y, y1, y2, ...) as well.
// The content of these vectors does not matter, because the plotter function
// unconditionally sets its calculated values into those vectors for later use,
// without looking at previous values, so we can leave the content uninitialized
// and only allocate vectors with the correct element size.
outConfig._transformedValues.resize(outConfig.channelCount);
// Resize each channel vector to the expected number of elements
const auto xChannelElementCount = (*outConfig.value)[0].size();
for (auto& channel : outConfig._transformedValues)
{
channel.resize(xChannelElementCount);
}
}

Expand Down

0 comments on commit a6858d1

Please sign in to comment.