Fix:Core:Prevent segfault(fixes #529)|Thanks Pini for the patch.