How to get the number of model's faces through C SDK?

Hey, all:
I wanna get the number of model’s faces through C API. And the following is my code segment:

VERTEX_API int getNumofFaces(const char* filename) {
	SUModelRef model = SU_INVALID;
	if (SUModelCreateFromFile(&model,filename) != SU_ERROR_NONE)
		return -1;
	SUModelStatistics* statistics = SU_INVALID;
	SU_CALL(SUModelGetStatistics(model, statistics));
	int number = statistics->entity_counts[statistics->SUEntityType_Face];
	return number;

However, it throws an exception: access violation reading xxx…So, what’s the right way to get the count of faces?

Thanks in advance.

Pointer initialization.

You could do this:

        SUModelStatistics statistics = SU_INVALID;
	SUModelStatistics* p_stats = &statistics;
	SU_CALL(SUModelGetStatistics(model, p_stats))
	int number = p_stats->entity_counts[p_stats->SUEntityType_Face];

or you could do this:

        SUModelStatistics statistics = SU_INVALID;
	SU_CALL(SUModelGetStatistics(model, &statistics));
	int number = statistics.entity_counts[SUModelStatistics::SUEntityType_Face];

This is incorrect either way:

SUModelStatistics* statistics = SU_INVALID;

Yes, that’s the answer! Thanks man.

It looks like a question of newbie… long time not to write code with C API :slight_smile: