Access violation on sprite

So I have the following function

void Game::drill(Brick *brick, PhysicsBody *body)
{
    ...
    CallFunc *deletion = CallFunc::create([&]()
	{
		brick->setOpacity(0);
		body->setCollisionBitmask(7);
		body->setContactTestBitmask(true);
		brick->setPhysicsBody(body);
	});
    ...
}

When I call the deletion callfunc, I receive an access violation: Access violation executing location 0x00000000.

Why?

must be out of scope. Place a break point and step through your code and check in the debugger that it is in scope at that time.

Exactly what slackmoehrle pointed out. You need to pass by value, not by reference, so use ‘=’ instead of ‘&’, like the following:

CallFunc *deletion = CallFunc::create([=]()
{ 
....

Thanks a lot, now it works. I’ve been struggling with this issue for 3 days now :grinning: