https://bugs.kde.org/show_bug.cgi?id=326289

Marcel Martin <m...@freenet.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |---

--- Comment #22 from Marcel Martin <m...@freenet.de> ---
Thanks so much for looking into this! Unfortunately, the crash is still there.

(Sorry for the late reply, but for some reason I wasn’t notified that this
report had been updated.)

However, your changes made it a bit easier for me to continue debugging this.
As it turns out, the problem appears to be that I have two jobs that have the
same id. That is, within getJobFinished(), the 'jobs' variable (KCupsJobs)
contains four jobs, and the first two have the same .id(). (They also have the 
same .name().) I have four jobs in total.

Here is what happens inside the for loop over the KCupsJobs (the JobModel is
initially empty, i.e. rowCount() == 0 at the start)

- Iteration/job 0: jobRow() for this KCupsJob returns -1, which means that the
job isn’t in the model. The job is inserted at index 0.

- Iteration/job 1: jobRow() for this KCupsJob returns 0 because this KCupsJob
has the same id as the one that was just inserted. updateJob() is called for
row 0. Then the condition in "if (job_row != i)" is true ("found at wrong
position") and the code tries to take row 0 and insert it at index 2. This
fails for some reason so that there are actually no rows in the model anymore
(rowCount() == 0). Perhaps insertRow() has undefined behavior when the given
row index is greater than rowCount()?

- Iteration/job 2: jobRow() for this KCupsJob returns -1 as it is a different
job. The code tries to insert it at index 2. insertJob() calls updateJob() with
pos = 2, which crashes at some point because rowCount() is actually 0.

I have no idea why the duplicate jobs exist, but they are also visible on
<http://localhost:631/jobs/>, so they’re real.

I’ve attempted to fix the problem in getJobFinished() by just inserting all
jobs when the model is empty:

if (rowCount() == 0) {
    for (int i = 0; i < jobs.size(); ++i) {
        insertJob(i, jobs.at(i));
    }
} else {
    // (previous loop here)

For me, this avoids the crash during startup. (I’m not suggesting this is a
proper fix.)

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to