Hi guys!

As I'm trying to get more used to structures, I've faced weird malfunction W1516.. Invalid memory area test ( test - function's name ).
For me code seems fine, but I still can't get it. Can you please poke me in a right direction? Thank you.

Here is a code:
Code:
#include <acknex.h>
#include <default.c>

#define PRAGMA_POINTER

var test(ENTITY *actor);

typedef struct RD {
	
	var id;	
	VECTOR vec;
	ENTITY *ent;
	
} RD;

void npc_event(){
	
	if(event_type == EVENT_CLICK){
		
		my->emask &= ~ENABLE_CLICK;
		my->event = NULL;
		
		test(my);
		
	}
	
}

void npc(){
	
	vec_set(&my->scale_x, vector(1, 1, 2));
	c_setminmax(my);
	set(my, TRANSLUCENT);
	my->emask |= ENABLE_CLICK;
	my->event = npc_event;
	
}

void test(ENTITY *actor){
	
	//RD *example = sys_malloc(sizeof(RD)); // randomly
	RD *example = sys_nxalloc(sizeof(RD)); // constantly
	
	example->id = 2;	
	vec_set(&example->vec, vector(-5, 5, 0));	
	example->ent = ent_create(CUBE_MDL, &actor->x, NULL);
	
	var counter = 3;
	
	while(actor){
		
		counter -= time_frame / 16;
		if(counter <= 0){ break; }
		
		wait(1);
		
	}
	
	if(example->ent){
		
		safe_remove(example->ent);
		
	}
	
	sys_free(example);
	example = NULL;	
	
	my->emask |= ENABLE_CLICK;
	my->event = npc_event;
	
}

void main(){
	
	video_set(800, 600, 16, 2);
	video_aspect = 1.333;

	d3d_lines = 1;
	warn_level = 6;
	fps_max = 60;
	
	level_load("");
	wait(3);
	
	vec_set(&camera->x, vector(342, 0, 140));
	vec_set(&camera->pan, vector(180, -13, 0));
	
	mouse_mode = 4;
	mouse_pointer = 2;
	
	ENTITY* ground_ent = ent_createterrain(NULL, nullvector, 100, 100, 1000);
	ent_setskin(ground_ent, bmap_fill(bmap_createblack(32, 32, 16), COLOR_GREEN, 100), 1);
	
	ent_create(CUBE_MDL, vector(0, 0, 32), npc);

}

I tried both sys_malloc and sys_nxalloc, but was getting W1516 from both (somehow malloc is hard to reproduce, but I remember getting malfunction from it too).


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung