Help| List loop through all creatures in range

How can this be executed?

Use grid searcher.

float range = 100.0f // 100 yard range (max is SIZE_OF_GRIDS)

std::list<Creature*> list;
Trinity::AnyUnitInObjectRangeCheck checker(obj, range);
Trinity::CreatureListSearcherTrinity::AnyUnitInObjectRangeCheck searcher(obj, list, checker);
obj->VisitNearbyGridObject(range, searcher);

for (std::list<Creature*>::const_iterator it = list.begin(); it != list.end(); ++it)
{
// code
}
obj can be any WorldObject

My current code:

void OnChat(Player *player, uint32 type, uint32 lang, std::string& msg)
{

    if(type == 1 || type == 6) //Say, Yell
    {
        WorldObject *obj = player->GetViewpoint();
        
        std::cout << "Hier" << std::endl;
        
        float range = 5.0;
        std::list<Creature*> list;
        
        std::cout << "Hier 2" << std::endl;
        
        Trinity::AnyFriendlyUnitInObjectRangeCheck checker(obj, player, range);
        
        std::cout << "Hier 3" << std::endl;
        
        Trinity::CreatureListSearcher<Trinity::AnyFriendlyUnitInObjectRangeCheck> searcher(obj, list, checker);
        
        std::cout << "Hier 4" << std::endl;
        
        obj->VisitNearbyGridObject(range, searcher);
        
        
        std::cout << "Hier 5" << std::endl;
        
        
        for (std::list<Creature*>::const_iterator it = list.begin(); it != list.end(); ++it)
        {
            (*it)->Say("Test", (Language)lang);
        }
        
        
        std::cout << "Hier 6" << std::endl;
        
        ChatHandler(player->GetSession()).PSendSysMessage("lang: %u, Msg: %s", lang, msg.c_str());
    }
}

Compilation is successful, but when i say sth ingame, the server prints this:

TC>TC>TrinityCore rev. 2ed0af7d752b+ 2015-01-25 15:26:30 +0000 (3.3.5 branch) (Unix, Release) (worldserver-daemon) ready…

Hier
Hier 2
Hier 3
Segmentation fault

and crashes. (It also crahes with [COLOR=rgb(102,0,102)]AnyUnitInObjectRangeCheck)

obj is NULL.

Viewpoint is not guaranteed to exist.