Homebrew Error 109 "Sprite GFX is already in use" when deleting sprite with NightFoxLib

NotTheOnlyRph

Member
OP
Newcomer
Joined
May 7, 2024
Messages
6
Trophies
0
XP
22
Country
France
Hello guys,

I am currently programming on the DS using LibNDS and NFlib, and when using the function NF_DeleteSprite(), i'm getting this error message:

1716321161868.png


Here's the code:

C++:
// Includes C++
#include <stdio.h>
#include <stdlib.h>

#include <time.h>

// Includes LibNDS
#include <nds.h>
#include <nds/touch.h>
#include <nds/input.h>
#include <fat.h>

// Includes NFlib
#include <nf_lib.h>

#define MAXSPRITES 32

int wait;

/*
-------------------------------------------------
    void() - Blocs de définition
-------------------------------------------------
*/

void Update()
{
        NF_SpriteOamSet(0);
        NF_SpriteOamSet(1);
        swiWaitForVBlank();
        oamUpdate(&oamMain);
        oamUpdate(&oamSub);
}

/*
-------------------------------------------------
    Main() - Bloque general del programa
-------------------------------------------------
*/

int main(int argc, char **argv) {

    float arrowposx;
    int arrowposy;
    int option;
    int start = 0;

    // Inicializa el random
    srand(time(NULL));

    // Pantalla de espera inicializando NitroFS
    NF_Set2D(0, 0);
    NF_Set2D(1, 0);  
    consoleDemoInit();
    iprintf("\n The Monty Hall Problem\n DS port by Rph\n\n Please wait for NitroFS to init\n\n\n (If it takes too much time,\n it probably doesn't work. See\n [PLACEHOLDER URL]\n for information.)");
    swiWaitForVBlank();

    // Define el ROOT e inicializa el sistema de archivos
    NF_SetRootFolder("NITROFS");    // Define la carpeta ROOT para usar NITROFS

    // Inicializa el motor 2D
    NF_Set2D(0, 0);
    NF_Set2D(1, 0);                // Modo 2D_0 en la pantalla inferior

    // Inicializa los fondos tileados
    NF_InitTiledBgBuffers();    // Inicializa los buffers para almacenar fondos
    NF_InitTiledBgSys(0);        // Inicializa los fondos Tileados para la pantalla superior
    NF_InitTiledBgSys(1);        // Inicializa los fondos Tileados para la pantalla inferior

    NF_InitSpriteBuffers();
    NF_InitSpriteSys(0);
    NF_InitSpriteSys(1);

    touchPosition touch;
    soundEnable();

       while(1) {
         
        touchRead(&touch);
       
        //Titlescreen
       
        NF_LoadTiledBg("bg/Top1", "Top1", 256, 256);
        NF_CreateTiledBg(0, 3, "Top1");

        NF_LoadTiledBg("bg/Bottom1", "Bottom1", 256, 256);
        NF_CreateTiledBg(1, 3, "Bottom1");

        NF_LoadSpriteGfx("sprites/Arrowbeta", 5, 32, 16);
        NF_LoadSpritePal("sprites/Arrowbeta", 5);
        NF_VramSpriteGfx(1, 5, 5, false);
        NF_VramSpritePal(1, 5, 5);
        NF_CreateSprite(1, 5, 5, 5, 32, 64);
       
        arrowposx = 32;
        arrowposy = 48;
        option = 1;
       
        while(1) {
           
                               
            if (arrowposx == 20) {
                arrowposx = 32;
            }
            else {
                arrowposx -= 0.5;
            }
           
            NF_MoveSprite(1, 5, arrowposx, arrowposy);
           
            Update();
           
            for (wait=0; wait<=60; wait++) {
               
                scanKeys();
                   
                if (KEY_UP & keysDown() || KEY_DOWN & keysDown()) {
               
                    if (option == 1) {
                        option = 2;
                        arrowposy = 112;
                        NF_MoveSprite(1, 5, arrowposx, arrowposy);
                        break;
                    }
                    if (option == 2) {
                        option = 1;
                        arrowposy = 48;
                        NF_MoveSprite(1, 5, arrowposx, arrowposy);
                    }
                }
               
                if (KEY_A & keysDown()) {
                    start = 1;
                }
            }
           
            if (start == 1) {
                start = 0;
                NF_DeleteSprite(1, 5); //Here happens the problem
                Update();
                MontyHall(option); //Forget about this function
                break;
            }
        }
        }
       
    return 0;

}
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    Psionic Roshambo @ Psionic Roshambo: @BigOnYa, FarCry 5 is an awesome game with multiple endings!