I have not really spent much time on this issue, but I have noticed one thing.
If I let the video play through and wait for the my_video_stopped() callback to be executed before I try to load the background image, then the out of memory error is thrown.
But if I manually stop the video using the jo_video_stop() function just 1 frame before the video ends and remove the callback, I am then able to load the background image into memory.
Although the video window is still being displayed over the background image it is not giving any memory errors.
https://youtu.be/LYE-Hb-WM8k#include <jo/jo.h>
#include <jo/video.h>
int viedo_draw_id;
int video_counter;
void my_draw(void) {
video_counter += 1;
if (video_counter < 385) {
// Yes, it consume a lot of memory during playing :)
jo_printf(0, 0, "Dynamic memory usage: %d%% ", jo_memory_usage_percent());
jo_printf(0, 1, "Sprite memory usage: %d%% ", jo_sprite_usage_percent());
jo_printf(0, 5, jo_get_last_error());
jo_sprite_draw3D(jo_get_video_sprite(), 0, 0, 170);
}
else {
jo_core_remove_callback(viedo_draw_id);
jo_sprite_free_from(jo_get_video_sprite());
jo_video_stop();
my_background();
}
}
void my_background() {
jo_clear_screen();
jo_img bg;
bg.data = NULL;
jo_tga_loader(&bg, "BG", "BG.TGA", JO_COLOR_Transparent);
jo_set_background_sprite(&bg, 0, 0);
jo_free_img(&bg);
}
void my_video_stopped(void) {
}
void jo_main(void) {
jo_core_init(JO_COLOR_Black);
video_counter = 0;
if (jo_video_open_file("SAMPLE.CPK"))
jo_video_play(my_video_stopped);
viedo_draw_id = jo_core_add_callback(my_draw);
jo_core_run();
}
EDIT:
I also modified the 'RING_BUF_SIZ' in the video.c file, which is why the video is now consuming less dynamic memory.