What you describe sounds a lot like "write access to a dangling pointer" or "write access to out of bounds array/list entries". The latter would maybe be caught by range checks. The former is rather hard to find.
If you have a dangling pointer (e.g. an object that was freed, but not nil'ed) then the memory where that object was will be re-used later. If then you write to the dangling pointer, then you overwrite the new data at that location. Effectively trashing that data. So when the code tries to use the trashed data, it will fail.
You don't always get the error, because sometimes the dangling pointer points to unused memory => and then no harm done.
You change any code at all, the order of things in memory changes, and the error moves... or hides.
There are a couple of means.
First heaptrc.
- Compile with -gh (project options / debugger / heaptrc - mem leaks)
- In menu Run > Run Parameters: Set the environment for your app to have HEAPTRC=keepreleased
That is probably going to get you some details, but it's more to confirm that you have incorrect mem access. It may not help much finding where.
You are on Linux. Lucky you. On Linux you can use valgrind (3rd party tool, can be installed to any Linux).
Compile your app with -gv (and without heaptrc).
Then outside the IDE run:
valgrind --tool=memcheck --num-callers=35 --log-file=mylog.trc ./yourapp
This will take some time. Your app will be crawling slow.
Do a few interactions with the app. You don't need to get an error, but you need to make sure the invalid code is run (if the error goes to unused mem, it still will be logged).
When done, in the IDE, menu View > Leaks and traces : load the logfile.
It will tell you when and where "freed" memory was accessed.
Mind there are entries like "4 bytes were accessed (READ) and one of it was outside an allocated block" => those are often false positives.
You are looking for WRITE to FREED mem.