04 Sep, 2010, ATT_Turan wrote in the 21st comment:
Votes: 0
The answer is no I haven't resolved it. The code works absolutely fine when I take out all calls to the event handler after the first one - I made the movement through the rooms work recursively and it functions perfectly. If I make the movement function create another event on the character, no matter how long the timer, it crashes with that memory error.

I figure there has to be some sort of subtle problem in the memory recycling within the event handler as shipped, but I've gone through it as carefully as I can and cannot find it. The function working recursively is obviously not how'd I prefer it (I don't love the people zooming around, and it doesn't give falling people a chance to catch themselves with spells, and it could crash if someone had a long enough fall). I have, however, run out of thoughts on how to make it work my way…


David Haley said:
Usually when it sees that you're freeing something twice, it can give you even the exact line where that piece of memory was freed.


Well, you've seen my output…it doesn't warn me about anything like that :cry:
04 Sep, 2010, David Haley wrote in the 22nd comment:
Votes: 0
Oh, right, it's been a while. I'd forgotten about that. :smile:

Well, if you're willing to share your code publicly or privately, and can provide very easy steps to reproduce, I might be convinced to take a look at it… it's easier to "drive" than to try debugging over a forum.
04 Sep, 2010, ATT_Turan wrote in the 23rd comment:
Votes: 0
The code for the event handler is Davion's in the repository, linked to in the first post.

The code I wrote that produces the memory bug is in the pastebin link in the first post (including one modification to the execute_char_event() function that comes with the event handler).

That code can be changed to work with no bug by replacing calls to event_move_apply() inside of event_move() with calls to event_move() (using the same arguments).

If any of that is confusing, you can provide me with an e-mail and I'll send my modified event.c file to it and you can follow Davion's original installation instructions.
04 Sep, 2010, David Haley wrote in the 24th comment:
Votes: 0
I was kind of hoping for something I could unzip, compile, and launch, so that I would only be spending time on the debugging part. Also, who knows what else you might have done that could subtly affect things. I've pm'ed you an email address. Please forgive me my laziness. :wink:
05 Sep, 2010, ATT_Turan wrote in the 25th comment:
Votes: 0
Not at all, your help is entirely appreciated. I'll send off something to you tonight.
05 Sep, 2010, Davion wrote in the 26th comment:
Votes: 0
I was taking a look at the event code some more, and I spotted something fishy. This is at the bottom of free_event, when removing an event from the global list.

found = FALSE;
if( event == event_list )
{ event_list = event->next;
found = TRUE;
}
if( event == event_last )
{ if(!event_list)
event_last = NULL;
else
for( tmp = event_list ; tmp ; tmp = tmp->next )
if(tmp->next == event)
tmp->next = event->next;
return;
}
if(!found)
for(tmp = event_list ; tmp ; tmp = tmp->next )
if(tmp->next == event )
tmp->next = event->next;
event->next = event_free;
event_free = event;
event->next_event = NULL;
return;
}


If the node is event_last, it removes it from the list then RETURNS. Which is probably not what I want to happen. Changing that to, "found = TRUE;" would probably yield expected results.

Ya know, looking back on that code now, 4-5 years later, I wonder, WTF was I thinking ;). (because to me, event_last, for both the local, and global lists looks to not properly be handled.)
05 Sep, 2010, ATT_Turan wrote in the 27th comment:
Votes: 0
…that's okay, Davion, I spent about half an hour going through that and I think I never noticed that return floating in there. It does not, however, seem to affect my problem.
05 Sep, 2010, David Haley wrote in the 28th comment:
Votes: 0
(Did you send anything? I didn't get anything – let me know if you did and I'll poke at my spam filters.)
05 Sep, 2010, ATT_Turan wrote in the 29th comment:
Votes: 0
I did just now.
05 Sep, 2010, David Haley wrote in the 30th comment:
Votes: 0
Oh, ok. Got it. :smile: I'll take a look later tonight most likely.
06 Sep, 2010, ATT_Turan wrote in the 31st comment:
Votes: 0
Thanks to the illustrious Mr. Haley, the problem seems to have been found. The event handler code has an extraneous call to free_string() inside of the event_new() function. This won't matter for an actually new event, but when it grabs the recycled event_free structure it'll be freeing a string that was already freed inside of free_event(). Both he and I have removed that function call and toyed around with my movement event and it seems to work beautifully.

Davion, will you be updating the code in the repository with these fixes, or should one of us make a comment on it for the benefit of others using the snippet?
20.0/31