Page 1 of 1

Memory Leak & Calc crash

Unread postPosted: 05 Sep 2021, 12:13
by Rankail
I can open my program and close it but whenever i open and close it multiple times it shows the waiting symbol and after a few seconds the calc in the emulator restarts. Whenever it does so it throws an error in the debugger:
Code: Select all
Warning (13a574d0): Data abort: address=0001002f status=01 instruction at 13a574d0.
The numbers are always a bit different.

The calc is cx 4.5.3.14.
There was also a problem where i would get a memory error after restarting a slightly other code around 10-20 times. I couldn't find any memory leaks though. So i spend the last 2-3 days "playing" around with the pointers. Changing from pointers to smart pointers and the other way around. Adding delete for all pointers i found. Nothing seemed to work 100% fine. Anyone can help me? I uploaded my code to github because i honestly don't know what to do anymore. :|
https://github.com/Rankail/nStateMachine

If you want to know anything about how the code should work or i missed some info please tell me

Re: Memory Leak & Calc crash

Unread postPosted: 06 Sep 2021, 16:26
by Vogtinator
You have a severe memory leak in Renderer::SetFont: It creates a new font based on the passed parameters, but never frees the old one.

What it should do is only create a font if necessary and take care of the old ones as well. I recommend to create all the needed fonts on startup and avoid dynamic allocation during runtime.
I also recommend to only draw if something changed and use the "idle()" function to wait for the next input event instead of drawing as fast as possible.

The data abort could be caused by a missing check for malloc failure, if it tries to use an invalid null pointer.