add_buffer() doesn't actually free the buffer?

Posted By: Florastamine

add_buffer() doesn't actually free the buffer? - 01/04/16 03:08

Currently I am having trouble with add_buffer(). It appears that although add_buffer() is called in free_buffer() to free the buffer that is supposed to contain the model data, the engine happily loads the model even after the buffer is freed.

Below is some sample code. Isn't the buffer supposed to be freed and the engine would complain about the missing model after it was freed?

Thanks for any insights.

Code:
#include <acknex.h>
#include <default.c>

const STRING *description = "[Q]: Free the buffer.\n[W]: Load the buffer\n[E]: Load the model.";
ENTITY *guard = NULL;

void *model_buffer = NULL;
long model_size = 0;

void buffer_free();
void buffer_load();
void model_load();

void spin();

int main(void)
{
	on_w = buffer_load;
	on_q = buffer_free;
	on_e = model_load;
	
	level_load(0);
	vec_set(&camera->x, vector(-256, 0, 0));
	
	while( !key_esc )
	{
		draw_text(description, 10.0, 10.0, COLOR_WHITE);
		
		wait(1.0);
	}
	
	add_new(); // Remove the buffer before exit.
	sys_exit(0);
}

void buffer_free()
{
	add_buffer( "./data/guard.mdl", NULL, model_size );   // Remove the buffer.
}

void buffer_load()
{
	model_buffer = file_load("guard.mdl", NULL, &model_size);
	
	if(model_buffer)
	    printf("model loaded with a total size of %f Kbytes.", (double) model_size / 1024);
	
	add_buffer( "guard.mdl", model_buffer, model_size );
}

void model_load()
{
	if(guard)
	    safe_remove(guard);
	    
	guard = ent_create("guard.mdl", nullvector, spin);
}

void spin()
{
	while(my)
	{
		my->pan += 5.5 * time_step;
		wait(1.0);
	}
}

Posted By: Wjbender

Re: add_buffer() doesn't actually free the buffer? - 01/04/16 21:47

doesnt look like its free'd , this always shows a size value.

Code:
void model_load()
{
	if(guard) safe_remove(guard);
	    
        if(model_buffer!=0l)printf("buffer!=null");
	
        guard = ent_create("guard.mdl", nullvector, spin);
}



if i set model_buffer to null it may ,however i see your point..

this doesnt seem to work either:
"If a buffer was allocated by the engine, it must be deallocated by file_load(NULL,buffer,NULL); before terminating the application."
Posted By: Florastamine

Re: add_buffer() doesn't actually free the buffer? - 01/09/16 06:01

Originally Posted By: Wjbender
doesnt look like its free'd , this always shows a size value.

Code:
void model_load()
{
	if(guard) safe_remove(guard);
	    
        if(model_buffer!=0l)printf("buffer!=null");
	
        guard = ent_create("guard.mdl", nullvector, spin);
}



if i set model_buffer to null it may ,however i see your point..

this doesnt seem to work either:
"If a buffer was allocated by the engine, it must be deallocated by file_load(NULL,buffer,NULL); before terminating the application."


Thanks for the input!

Yes, I also think that the buffer isn't freed (trying both add_buffer( buffer_name, NULL, buffer_size ); or file_load( NULL, buffer, NULL );, both didn't work). it's very weird.

A bug maybe? If someone else can verify this, I'll re-post it under bug hunt.
Posted By: Wjbender

Re: add_buffer() doesn't actually free the buffer? - 01/09/16 11:08

I would suggest you get another opinion first perhaps if you like.

I do not know if the lifetime of said buffer is "suppose" to outlive until the application/level end.
© 2024 lite-C Forums