There are a lot of things that could have been written better or different, but without trying to compile this myself, there is something that really bothers me and i would say this could potentially result in your crash:
You spamforce the boss an attackorder here on every update diff.
The more i think about this, the more i wonder where he even gets "target" from in this case? That should not even compile.
In general, there is a pretty basic and simple pattern you can follow in UpdateAI:
void UpdateAI(uint32 diff) override
{
if (!UpdateVictim())
return;
events.Update(diff);
if (me->HasUnitState(UNIT_STATE_CASTING))
return;
while (uint32 eventId = events.ExecuteEvent())
{
switch (eventId)
{
case EVENT_NAME:
stuff that should happen;
break;
default:
break;
}
if (me->HasUnitState(UNIT_STATE_CASTING))
return;
}
DoMeleeAttackIfReady();
}