This week I worked on some list strucks. First one was backgroundIncrustStruct, that holds previous and next pointers, and the variables that composes backgroundincrust. I thought having the list and the class together complicates code too much, so I decided to split it in two. I had some concerns but everything worked out, and I decided to go on, trust the original engine developers.
After trying to do the same to cellStruct, I had a segmentation fault. Splitting a Struct this way creates a huge diff since you have to edit every line that has any use of it to get it to compile, so I had no idea what got wrong.After reading the code several times did not help, I started with running with debug on, but it gave me nothing. Then I tried gdb, to debug the code, and it showed me a line of if statement (if (si->_cell->type == -1)). At first, it seemed odd, since it did not assign anything, but after giving some though, I realise that there was a CellListNode that do not has a Cell, so any read attempt to its members causes segmentation fault. I have go over and over on the code but addNode function creates and assigns Cells for every node. I added some debug messages,that confirmed every addNode run assigning a cell. I read backtraces, that did not help a bit. The cause was so obvious, it was too hard to see.
The only node that is not created by addNode is Head. In both lists (backgroundIncrust and Cell), head created manually, and used for previous and next pointers only so it do not have a object assigned to it. In backgroundIncrustList, methods directly pass head and start working with next node, which was my concern at the first step, but in CellList, methods does not pass head, although it never passes conditional statements that causing an empty first round in the loop. Since I split the CellStruct, the conditional statement tries to read a value from a null pointer, that causing segmentation fault at start of the first loop.
I can fix this with a few lines, just assign an empty Cell to head, but changing this behaviour, and making use of the head nodes is a better solution, so instead of adding and empty object just to prevent segmentation faults, I will alter the method to add and use actual objects to head.
In this few days a lot has happened in ScummVM front. Tiqpit, the other GSoC student has stopped working on is project, and also ScummVM's co leader fingolfin has retired. I wish both of them good luck in their lives..