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.
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); } }