view src/mbaf/mbapp.c @ 489:23c7667b3ec0 Android_Skia

Fix a potential bug when destroy a rdman. When a rdman is dirty, free shapes and coords works specially. Objects are append to a free list. They are not real freed until rdman being clean. redraw_man_destroy() free shapes and coords with free functions of them. If rdman is dirty when destroy it, objects would be leaked. The changeset make rdman clean before free shapes and coords to make objects being freed correctly.
author Thinker K.F. Li <thinker@branda.to>
date Sun, 22 Nov 2009 20:41:27 +0800
parents af4b506ad56f
children 586e50f82c1f
line wrap: on
line source

#include <mb.h>
#include <mb_af.h>

mbaf_t *mbaf_init(const char *module, const char *module_dir)
{
    mbaf_t *app = (mbaf_t *) malloc(sizeof(mbaf_t));
    void *rt;

    rt = backend.init(":0.0", 800, 600);
    if(rt == NULL)
	return NULL;

    sprite_set_search_path(module_dir);

    app->rt = rt;
    app->rdman =  backend.rdman(rt);
    app->kbevents = backend.kbevents(rt);
    
    app->rootsprite= sprite_load(module,app->rdman, app->rdman->root_coord);
    if(app->rootsprite == NULL) {
	backend.free(rt);
	free(app);
	return NULL;
    }
    
    rdman_attach_backend(app->rdman, rt);
    MB_SPRITE_GOTO_SCENE(app->rootsprite, 1);
    
    return app;
}

void mbaf_set_data(mbaf_t *app,void *data)
{
    app->private = (void *) data;
}

mb_tman_t *mbaf_get_timer(mbaf_t *app)
{
    return backend.tman(app->rt);
}

void mbaf_loop(mbaf_t *app)
{
    /*
     * Start handle connections, includes one to X server.
     * User start to interact with the application.
     */
    backend.loop(app->rt);

    /*
     * Clean
     */
    backend.free(app->rt);
    free(app);
}