I can not simulate this to send you because my project is very big.The strange thing is that the error only happens with MadExceptif I disable MadExcept the error does not happen.if I activate EurekaLog the error does not happen either.

Is this a problem in this version I'm testing from madExcept ?

See this video attached.where I test with the active madExcept gives the KeyViolation error if I disable the MadExcept error does not happen.

I did not show it on the Video, but EurekaLog does not show any errors.

That's clearly a bug in your program. Enabling madExcept may change timing a bit which can make some bugs visible which weren't visible before.

What you can see is that the crash is not in the main thread, but in a secondary thread ("TThread_SalvaGrid"). The crash occurs because your main thread is already in the process of shutting down the process, which includes destroying/finalizating a lot of things including the memory manager (!). But there's still the "TThread_SalvaGrid" thread running at the same time, while your main thread is destroying stuff behind your secondary thread's back!

Your program should wait for all secondary threads to be completed before shutting down. Or alternatively put the secondary threads to sleep. If any of those threads e.g. try to access the memory manager after your main thread has already finalized the memory manager, there will be a crash.

But in case you didn't understand me clearly earlier: Your program has a bug! It is bad programming practise to have secondary threads still actively running while your main thread is in the process of finalizing/destroying all resources. If you didn't get shutdown crashes before, you've just been lucky, because the way your program currently works, you have to expect that shutdown crashes may occur randomly!!

Think about it: If your main thread finalizes the memory manager, any call to GetMem or FreeMem will crash. If at this moment one of your secondary threads are still running, and if they call GetMem or FreeMem, they will crash. So as a result it is very clear that once the main thread has started finalization, no secondary thread which accesses any Delphi RTL or VCL resources should still be actively running. Makes sense?