http://wikisend.com/download/686600/test.zipI couldn't find a issue , what are you doing different in yours?
terrain_get_z could only have a few possible empty pointers/whatever , a non existing entity or empty min max I believe ..
but I did what you said and didn't get the same issue , you must be using / doing something more than just that , are you using water planes and shaders or something ,something is missing from your explanation.