Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (7th_zorro, dr_panther), 1,173 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
add_buffer() doesn't actually free the buffer? #457189
01/04/16 03:08
01/04/16 03:08
Joined: Apr 2015
Posts: 20
Vietnam
F
Florastamine Offline OP
Newbie
Florastamine  Offline OP
Newbie
F

Joined: Apr 2015
Posts: 20
Vietnam
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);
	}
}


Last edited by Florastamine; 01/04/16 03:19.
Re: add_buffer() doesn't actually free the buffer? [Re: Florastamine] #457202
01/04/16 21:47
01/04/16 21:47
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
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."


Compulsive compiler
Re: add_buffer() doesn't actually free the buffer? [Re: Wjbender] #457247
01/09/16 06:01
01/09/16 06:01
Joined: Apr 2015
Posts: 20
Vietnam
F
Florastamine Offline OP
Newbie
Florastamine  Offline OP
Newbie
F

Joined: Apr 2015
Posts: 20
Vietnam
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.

Re: add_buffer() doesn't actually free the buffer? [Re: Florastamine] #457248
01/09/16 11:08
01/09/16 11:08
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
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.


Compulsive compiler

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1