Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: segfault with multichannel custom series #2307 #2345

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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