epezent / implot

Immediate Mode Plotting
MIT License
4.66k stars 520 forks source link

SetupAxisTicks failing due to SetupLocked #300

Closed dgm3333 closed 2 years ago

dgm3333 commented 2 years ago

I've just upgraded to the latest ImPlot. However I can't get SetupAxisTicks to work. Even when I move it to be the first ImPlot call it asserts an error

eg with this code:-

static const double yticksSecs[] = { 0, 3600, 7200, 10800, 14400, 18000, 21600, 25200, 28800, 32400, 36000, 
39600, 43200, 46800, 50400, 54000, 57600, 61200, 64800, 68400, 72000, 75600, 79200, 82800, 86400 };
static const char* ylabelsHrs[] = {
"00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", "07:00", "08:00", "09:00", "10:00", 
"11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00", "23:00", "24:00"
};
static const uint16_t countOfYTicks = _countof(yticksSecs);
ImPlot::SetupAxisTicks(ImAxis_Y1, yticksSecs, countOfYTicks, ylabelsHrs);

it triggers this assert:-

void SetupAxisTicks(ImAxis idx, const double* values, int n_ticks, const char* const labels[], bool show_default) {
    IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != NULL && !GImPlot->CurrentPlot->SetupLocked,
                        "Setup needs to be called after BeginPlot and before any setup locking functions (e.g. PlotX)!");
epezent commented 2 years ago

Hi, sorry you're having an issue. I can't seem to reproduce the issue. Here is my code and result:


if (ImPlot::BeginPlot("Test"))
{
    static const double yticksSecs[] = {0, 3600, 7200, 10800, 14400, 18000, 21600, 25200, 28800, 32400, 36000,
                                        39600, 43200, 46800, 50400, 54000, 57600, 61200, 64800, 68400, 72000, 75600, 79200, 82800, 86400};
    static const char *ylabelsHrs[] = {"00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", "07:00", "08:00", "09:00", "10:00",
                                        "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00", "23:00", "24:00"};
    static const uint16_t countOfYTicks = _countof(yticksSecs);
    ImPlot::SetupAxisTicks(ImAxis_Y1, yticksSecs, countOfYTicks, ylabelsHrs);
    ImPlot::EndPlot();
}

image

Can you share your full code?

dgm3333 commented 2 years ago

There are something like 20-30000 lines of interlocked code and most plots required multiple large data files, so sharing a working example isn't going to be possible. Also turns out it's not just the ticks - there are numerous implot setup lock assert errors throughout my application and I have had to comment out numerous tick and axis changes to make it work.

Edit - I hadn't noticed the BeginPlot call had been depreciated, so I hadn't recoded those, and on an initial test it seems that moving everything withing the Begin/EndPlot blocks and using (eg) SetupAxisLinks rather than SetNextAxisLinks sorts my issue. I'll test over the next few days but meantime fingers crossed .