Another week pass, with a lot of breaking and fixing. The good part is, I am really getting used to this.
The first one was a obvious mistake, I forgot to increase the iterator I use. When you try to exit, the removeAllScripts function is called, and it tries to free the first element a second time.
Second one was a save load problem. I was using iterators, and checking if the iterator equals to end(), but loading creates and adds a new node in every loop, so it never ends. Since the number of elements is written in the save file, and read before the loop, I just changed the check in the for body.
I was having random segmentation faults that I did not get what triggers them. While testing the save-load, I realise that they are happening a lot more now. So I checked if save load has something to do with it. The problem was, currentScriptPtr was not null, but it should be. There are two assignments to it in the engine. One before starting a script, that assigns it the address of the script to run, and runs it in a while, then at the end of the while, another assignment that makes currentScriptPtr’s value NULL. How a variable, that only function that assigns a value to it also assigns null to it before ending, can have non null value? The answer is loading. If you load a save before the running script finishes, the pointer is not null, and that causes a segmentation fault (or worse). Just added another assignment to be sure the value is null.
The last problem was another segmentation fault, that happens at start of the game. I was trying to move persoTable to vars.h/cpp when this problem emerged, so I checked if it is a initialization problem, and found out, even after assigning null to all elements, the first element is not null, but 0xFFFF0000. Then I debugged with gdb, and watched the address. Then I realise, before I modified it, there was always a first element in the list, but now, there might not be, and since I did not add a check for that, a assignment to first element was overwriting to the persoTable.
As you can see, there were a lot of problems, but I do not feel down when I found an error any more. This is a part of the job I guess, nothing to worry about.