You have a segmentation fault because you try to access memory that was deleted beforehand.
The problem is the else case of the "if (ttmsg->getTreeId() != msgid)" statement.
You delete the ttmsg there ("delete ttmsg;"), but after the else statement, you still access the ttmsg ("msgid = ttmsg->getTreeId();").
You can either move the "msgid = ttmsg->getTreeId();" function somewhere else or omit the "delete ttmsg;" to avoid the segmentation fault.
I've added these comments into a slightly "cleaned up" version of your example, couldn't run it at first under OMNeT 4.6, had to create a new project.