Error Debugging with OpenGL
-
Well, I have this error debugging in QtCreator, I show screenviews:
It just break in this line:
tool_list[i] = new QLabel();
with tool_list initialized as
QList <QLabel*> tool_list;
tool_list.reserve(NUM_TOOL_MAX);The program rules good in release, but not in debug.
-
Hi and welcome to devnet,
Are you sure you intialized every variable properly ?
-
Yes, the program rules well in release, only fails in debug.
-
Please show the backtrace of the crash.
-
-
Did you check the size of
tool_list
?And by the way, why not use append rather than a fixed sized that might never been reached thus consuming memory for nothing ?
-
@SGaist said in Error Debugging with OpenGL:
And by the way, why not use append rather than a fixed sized that might never been reached thus consuming memory for nothing ?
Yes, it's 0 at this point (in release and debug).
But I don't understand because it work in release and the program run, but not in debug
-
So basically you are trying to access element 0 of a vector of size 0 ?
That won't work.
In release mode you will be getting a vector of unknown size if NUM_TOOL_MAX is not properly initialised. It will contain garbage as you have to explicitly initialise variables.
-
I'm completly sure that NUM_TOOL_MAX is initialised, even I tried
tool_list.reserve(3);
tool_list[i] = new QLabel();And doesn't work.
The code isn't mine, so I don't know why is like this, any suggestion for initalize the array?
-
Well... Unless you have very good reasons for that, just don't and use append so your tool_list vector will grow as much as you add QLabels.