Fixed crash in ForEachEntityInBox API.

Fixes #1511.