Re: [r2972] Crash when building tunnel entrance
Reply #4 –
So it's one of those bugs...
I cranked up the debug level for tunnelbauer.cc from 1 to 2, so that it would be easier to debug. That drastically reduced my ability to reproduce the crash, but I am still able to trigger it by trying again and again until I succeed. According to gdb, the immediate cause of the crash is wrong data in zv. In the debugging session I have open now, it contains x = 3176 and y = 348, which obviously is bad for a 1024x1024 map. These values were fetched, already corrupted, from koord::from_hang[12]. They differ from crash to crash. Something seems to be writing where it should not, but what and why only to koord::from_hang[12]? I'll try to dig deeper.
According to gdb, freelist_t::putback_node is the culprit. For some reason list ends up pointing to koord::from_hang[12]. Comparing putback_node with gimme_node, I noticed the following difference that I think is to blame:
gimme_node:
size = max( min_size, size );
size = (size+3)>>2;
size <<= 2;
// hold return value
nodelist_node_t *tmp;
if(size>MAX_LIST_INDEX) {
switch(size) {
putback_node:
size = max( min_size, size );
size = ((size+3)>>2);
if(size>MAX_LIST_INDEX) {
switch(size) {
In gimme_node, size is shifted right then left, while in putback_node, it is just shifted right. But both compare it against the same constants afterwards. As far as I can tell, gimme_node does it right, while putback_node ends up going beyond the end of the all_lists array.