Update: I think I have most of the right code, but I still can't figure it out.
EXECUTION CODE IN MAIN.C:
#include "video.h"
#define jo_extended_ram_cartridge_type(CART_32MBits)
void jo_main(void)
{
jo_core_init(JO_COLOR_Black);
jo_core_suspend();
// jo_malloc(sizeof(int));
jo_core_add_callback(my_draw2);
jo_core_add_callback(my_video_stopped);
jo_core_add_callback(jo_main2);
if (jo_video_open_file("SAMPLE.CPK"))
jo_video_play(my_video_stopped);
jo_free((void*) video);
jo_core_suspend();
...blablabla
}
HEADER FILE:
#ifndef __VIDEO_H__
# define __VIDEO_H__
#include <jo/jo.h>
#define jo_extended_ram_cartridge_type(CART_32MBits)
const int *video;
void my_draw2(void)
{
video = jo_video_open_file; //0x06024970 0x044 0x80 0x013 0x1F8
const int *video = (const int*) jo_malloc(268000*sizeof(int));
if(video == NULL)
{
jo_printf(1, 2, "Unable to allocate memory", jo_get_last_error());
// jo_printf(0, 1, "Address of video variable: %d\n", *video);
// return JO_NULL;
}
// Yes, it consume a lot of memory during playing :)
jo_printf(0, 0, "Dynamic memory usage: %d%% ", jo_memory_usage_percent());
jo_sprite_draw3D(jo_get_video_sprite(), 0, 0, 170);
}
void my_video_stopped(void)
{
jo_printf(0, 1, "Done.");
}
void jo_main2(void)
{
jo_core_init(JO_COLOR_Transparent);
jo_core_add_callback(my_draw2);
// if (jo_video_open_file("SAMPLE.CPK"))
// jo_video_play(my_video_stopped);
jo_core_run();
}
#endif /* !__VIDEO_H__ */
/*
** END OF FILE
*/
Other than that, I added JO_COMPILE_WITH_RAM_CARD_SUPPORT to my makefile. I think I'll start working on a different approach. I think if I make it a separate video C file in a different folder, I might be able to get it to work. I'm just about done for today. I had to make one of the background colors transparent, because most of the time the error information was getting covered by black all over the screen. I am getting two errors: NULL pointer in jo_free, and GFS cannot determine file size.
I downloaded the demo.
You've got a few problems in this code, mainly too many callbacks. Way too many. You should be program-controlling whether or not things run inside a "game_loop" function. You shouldn't need more than 1 callback for the game, and 1 for the video. The bad pointer is because you are working with too many callbacks, and removing some of them. I don't want to be too harsh, you definitely have something, and I wish you the best of skills.
Secondly, BACKGROUND.H is consuming too much memory. To be precise, it is consuming about 600KB of high memory. There simply is not enough memory for the video to play when you include the background like that. Even if Jo engine is passing it off to VDP2, since it is included in the program itself, it is not an area available to memory allocation by default.
You MUST use binary files for ALL models, sprites, textures, and background data. To do this you should look at XL2's model loading tools and demos.
If you don't do this, you will continue to face mysterious crashes from SBL/SGL functions that basically destroy everything whenever they are out of sectors to run with, since Jo engine is front-loaded into high memory.
/e: When you move to program-controlled binary file loading, you should be able to use LWRAM for your project, even if the CPK eats up all of high memory you might not need that.
And, in that circumstance, your massive VDP2 background can be overwritten in LWRAM since it doesn't need to be there anymore.
Lastly, Jo Engine is not designed to have videos be program-controlled, as we thought it could be. You MUST load the CPK ONLY ONCE. Jo designed it to be a part of the program that is run, and then ignored. If it is inside a system callback, you're going to have trouble. As far as I have been able to test, this is the only correct way to play a video:
jo_core_init(JO_COLOR_Black);
if (jo_video_open_file("SAMPLE.CPK")){
jo_video_play(video_stop);
}
jo_core_add_callback(my_video);
Your error code 101 is the following:
CPK_ERR_OUT_OF_HANDLE = 0x00000101,/* ハンドル売り切れ */
Essentially that means when you have it as part of a system callback, too many CPK handles are created since it's running every frame.
I haven't fixed your problem, but hopefully I have armed you with enough information to proceed.
/e: a million edits
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.