// retrieve pointer to class instance
if(_class != 0 && function->type != Function::CONSTRUCTOR) {
out << ind << "SQUserPointer data;\n";
- out << ind << "if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, 0))) {\n";
+ out << ind << "if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, 0)) || !data) {\n";
out << ind << ind << "sq_throwerror(vm, _SC(\"'" << function->name << "' called without instance\"));\n";
out << ind << ind << "return SQ_ERROR;\n";
out << ind << "}\n";