Raycasting

I am trying to implement raycasting but it gives me an error asoon as it begins iterating through the shapes I am not even sure if I am doing it right.

Code:
void PlayState::CreateLaser(b2Vec2 position, float rotation, b2Vec2 direction, int ID)
{
   b2Segment segment;
   segment.p1 = position;
   b2Vec2 endPoint;
   endPoint.x = position.x + direction.x*10;
   endPoint.y = position.y + direction.y*10;
   segment.p2 = endPoint;

   SpriteInstance *spriteInstance = new SpriteInstance(game->app->GetSprite("explosion"), position, rotation);
   Object* obj = new ProjectileLaser(spriteInstance, NULL, 1, ID);
   b2Shape *shapeArray;
   int shapes = world->Raycast(segment, &shapeArray, 20, false, NULL);
   for(int x = 0; x < shapes; x++){
      ((Object*)shapeArray[1].GetBody()->GetUserData())->HandleCollision(this, *obj, 0);
   }
}
Shape array actually needs to be a array.
b2Shape *shapeArray[20];
int shapes = world->Raycast(segment, shapeArray, 20, false, NULL);
voila! Such a simple solution thanks ^_^! It works now, is there a way to change the width of the ray?

On a side though somewhat related question how would you guys go about creating the sprite for a laser beam?
If
A) The entire laser appears instantly from beginning to end
or
B)The laser shoots out progressively.

I've tried to think of a good way to approach this but can't think of anything good.

Thanks.

Original thread: https://box2d.org/forum/viewtopic.php?t=2915