Problem is it won't even enter the procedure when I try to debug as soon as I hit F8 on the second line it gives me the error.
F7 is to enter.
F8 will step over, but not if something goes wrong inside. Though the debugger might stop, and show you where it went wrong. But not always.
To use the debugger, set debug type info to "dwarf with sets"
--
So use F7. Step in.
Before each step, have a close look at all the variables, parameters, locals... Maybe one of them is not what you expect.
Have you made sure the list, and all other objects involved are indeed created before the call? Yes I know, the firs call uses them too. But that does not mean anything. Could be luck.
If you deal with an uninitialized object, the code may crash, or may work. It may work once, but not twice....
Here is one thing to consider:
It is also possible that some code - even completely unrelated code - goes wrong, and due to uninitialized or range violation writes to memory it does not own. Then the error happens at some random place later. And moving code around may (or may not) hide the problem.
---
Have you set all the debug checks (range, object ... checking)? -CRriot -gt (also try -gtt or -gttt)
Turned optimization to zero -O-
Added Heaptrc -gh (additionally search the forum for "keepreleased" option of Heaptrc)
If you are on Linux, instead of using Heaptrc, you can use valgrind.
Compile with -gv and then start your app from console: valgrind --tool=memcheck yourapp EDIT: posting overlapped / you are on Win