help with black screen

SGDK only sub forum

Moderator: Stef

Post Reply
danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

help with black screen

Post by danibus » Thu Dec 02, 2021 11:25 am

Hi there

I'm currently developing my own game. Every stage is already done and I can start game from beginning and finish it (I call this "first game loop").

But then when I start again to play ( "2nd game loop"), sooner or later, I found a black screen, with no sprites loaded in VRAM (but background tiles are loaded). CPU is working, I check 68k and it's working in a sort of loop. Then game is active, but nothing happens.

I tried to modify code. When I "fix/change" something in one stage, black screen appears in another stage.

I'm not using dynamic memory. Just in the begining I load my own config.h file with some global variables and some global structs, after that every stage.c has its local variables and they are destroyed after leaving function.

Also I track every sprite created and release before finishing stage. Also using VPP_init() after finishing every stage.
I though about tileSets, but I'm releasing ( Mem_free()/free() functions ) before leaving every stage using tilesets so.... I'm lost

Would you be so kind to help me?
  • At this moment only solution is making a hard reset when finishing game... but I want to know what is wrong and where is the problem.
    Take note still don't using music/sfx, not using Z80 at all.
    Take note using old sgdk release, I modify code to use lastest sgdk, problem still there, so I return to old sgdk as it0s not sgdk related.


This is my skeleton stage function:

Code: Select all

void stageXX(){

    SYS_disableInts();
    VDP_setScreenWidth320();
    SPR_init();
    Game.time = 0;
    Game.level = XX;

    VDP_setPaletteColors(0, (u16*) palette_black, 64);
    memcpy(&Game.palette[ 0],  stage1.palette->data,          16 * 2);
    memcpy(&Game.palette[16], sprite_player.palette->data, 16 * 2);
    memcpy(&Game.palette[32], sprite_xxxxx.palette->data,  16 * 2);
    memcpy(&Game.palette[48], sprite_yyyyyy.palette->data, 16 * 2);

    VDP_drawImageEx(PLAN_B, &stage1,  TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, Game.index_planB), 0, 0, FALSE, TRUE);
    Game.index_planA   = Game.index_planB + stage1.tileset->numTile;

    ..similar to PLAN_A...

    create_IU();
    create_player();          
    ....all create_functions() here...

    VDP_fadeIn(0, (4 * 16) - 1, Game.palette, 60, FALSE);
    VDP_waitFadeCompletion();

    SYS_enableInts();

	//main stage loop
	while (1) {
        control_IU();
        control_read_pad();
        control_player();
        ...all control_functions()... here

        Game.time++;

        if(Game.points>LIMIT) break; //to NEXT stage

        SPR_update();
        VDP_waitVSync();
	}

	//borra todo antes de terminar la fase
	delete_player();
        ...all delete_functions();... here  //release sprites

      //free memory tilesets (only if necessary)
      MEM_free(Game.tileset01);
      Game.Estructura1 = NULL;


    VDP_setHilightShadow(0);    //Disable HL/S mode (only if necessary)

    //reset VDP indexs
    Game.index_planA   = 1;
    Game.index_planB   = 1;
    Game.index_planTop = 1;

    VDP_init();
}

cloudstrifer
Very interested
Posts: 118
Joined: Mon Feb 19, 2018 7:31 pm

Re: help with black screen

Post by cloudstrifer » Fri Dec 03, 2021 7:50 pm

Its not easy.

I'm using Gens Kmod for debugging.
I can try to help you using Teamviewer or AnyDesk.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: help with black screen

Post by Stef » Sat Dec 04, 2021 10:21 pm

I will say it's probably an issue with variable initialization / initialized state.
But why just don't do a "hard reset" on completion ? so you're sure to restart in a perfect initialized state :)

danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

Re: help with black screen

Post by danibus » Sat Dec 04, 2021 11:21 pm

cloudstrifer wrote:
Fri Dec 03, 2021 7:50 pm
Its not easy.

I'm using Gens Kmod for debugging.
I can try to help you using Teamviewer or AnyDesk.
Thanks for your help, also use GensKmod. No need to Teamviewer, just wanna some clue to solve by myself.

danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

Re: help with black screen

Post by danibus » Sat Dec 04, 2021 11:22 pm

Stef wrote:
Sat Dec 04, 2021 10:21 pm
I will say it's probably an issue with variable initialization / initialized state.
But why just don't do a "hard reset" on completion ? so you're sure to restart in a perfect initialized state :)
Thanks, I will check every variable.
I can do hard reset, but I want to save high score.
Also want to know where is the problem, sure a silly mistake.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: help with black screen

Post by Stef » Sun Dec 05, 2021 2:26 pm

To be honest handling correctly soft reset without resetting everything can be tricky, it's easy to miss some uninitialized variables !

danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

Re: help with black screen

Post by danibus » Sun Dec 05, 2021 11:03 pm

Reset was last option.

First attempt was just end game (just finishing game or player dead), and then start main loop but no way so I try to reset.
Very very strange. I think my C is rusty, because I think all variable all properly initialized.
Will do a second check but... if there is some "crazy" variable, why is working well first time? :mrgreen: I know I know....

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: help with black screen

Post by Stef » Mon Dec 06, 2021 4:01 pm

Note that recent SGDK version are also more stable in general, so here depending on which version you are, you may also work with the old SGDK bugs too :-/

danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

Re: help with black screen

Post by danibus » Mon Dec 06, 2021 10:27 pm

I know, but I think is not SGDK fault, just my rusty C.
One month ago I make all necessary changes to use last SGDK version but the result was the same.
Then I back to "old SGDK" because I want to finish this game and after that start new project with lastest version.

I'm afraid I have to start with C from scratch, because I use to make small programs (1 file) and now have lot of .c and .h files, small mess, maybe this is what is going wrong.

Post Reply