PDA

View Full Version : BeginRemoveRows crash on deployment



Nekreg45
10th September 2018, 21:43
This is my first post on here. I have ran into an interesting issue that I haven't been able to figure out for a couple of weeks. After trying many different things and reading lots of posts, I am now hoping somebody on here has an idea.

I have a crash that only occurs on the deployed version of the software on computers that do not have Qt installed. I have used the Depends program for figuring out which DLLs I needed and recently tried using windeployqt as an alternative. My program is able to launch fine and run normally. However, there is a particular sequence of events I do that causes a crash only on the deployed version.

I have used a program called DebugView and was able to trace the exact line that the program crashes. It crashes on a BeginRemoveRows statement. The code looks like the following in this function:


bool AMPModel::removeItems(int position, int rows, const QModelIndex &parent)
{
AMPModelItem *parentItem = getItem(parent);
bool success = true;

beginRemoveRows(parent, position, position + rows - 1);
success = parentItem->removeChildren(position, rows);
endRemoveRows();

return success;
}


I have outputted the variables, the moment before the crash and get the following:
position = 5
rows = 1
I also outputted the number of children of the parentItem which is 6. The QModelIndex exists, and so does the parentItem after the getItem function.

I get the same variable output while running in debug mode on my development computer. However, it does not crash nor does running the same compiled version on that computer crash.

The overall picture of what I'm doing is that I have a model that contains my data and I'm switching between two ways of viewing this model (a tree view and a graphical view that I created). It seems to crash when I click within the tree view (just select any item), switch to the graphical view, and try to delete an item. If I do not select an item within my tree view, then I do not get the crash.

If anybody has any suggestions on what to try, I would really appreciate it. If you need more clarification, I would be happy to provide it.

Thanks!

d_stranz
12th September 2018, 17:09
I am guessing that the problem has nothing at all to do with the code you posted. If everything checks out valid in both debug and release modes, then it is probably OK.

What I think is happening is that you have an uninitialized pointer or other variable that gets used or that another part of your program is corrupting memory and it causes a crash that is apparent only in release mode.

When you compile and run in debug mode, your code gets instrumented with all sorts of things to help in the debugging process - variables and pointers get initialized to known, bogus values, stack trace code gets inserted, etc. Memory usage and layout are different. It isn't the same program as the one that gets built for release mode.

So first rebuild your program with the highest warning level. Second, add checks to make sure that every pointer you use is valid before you call through it (you aren't doing that in the code you posted - you just assume "parentItem" is valid...). Third, check that calling arguments are valid before using them (like "position", and "rows"). Don't just do this via the debugger or print statements that you later remove. Those don't test your actual use conditions. Put in conditional statements to check it in the code and don't make the call if they aren't valid. In debug mode, you can use asserts for this, but that doesn't help in release mode.