Les membres ayant 30 points peuvent parler sur les canaux annonces, projets et hs du chat.
La shoutbox n'est pas chargée par défaut pour des raisons de performances. Cliquez pour charger.

Forum Casio - Autres questions


Index du Forum » Autres questions » miss read error
Simnon Hors ligne Membre Points: 66 Défis: 0 Message

miss read error

Posté le 29/08/2025 12:12

imt trying to scan a 4x4 2d array for 0s using a dynamic array, but i get a miss read error when i run it on my calculator (9860giii), it happens on the line with krealloc
Pos *FreeP = NULL;
    int FreePItems = 0;
    for(int y=0; y<=3; y++){
        for(int x=0; x<=3; x++){
            if (field[y][x]==0){
                FreePItems++;
                FreeP = krealloc(FreeP, FreePItems*sizeof(Pos));

                FreeP[FreePItems-1].x = x;
                FreeP[FreePItems-1].y = y;
                
                
            }
        }
    }



Lephenixnoir En ligne Administrateur Points: 25372 Défis: 174 Message

Citer : Posté le 29/08/2025 12:15 | #


The snippet looks good. A proper MWE would be welcome. Also what address is the miss for? It's not obvious where the memory access is on that line.
Mon graphe (27 Juin): (MQ || Rogue Life) ; serial gint ; passe gint 3 ; Azur ; ...) || (shoutbox v5 ; v5)
Simnon Hors ligne Membre Points: 66 Défis: 0 Message

Citer : Posté le 29/08/2025 12:18 | #


the calculator says PC:00303846 ; TEA:089108c1 if that's what you're asking, i will try to make a minimal working example rn
Simnon Hors ligne Membre Points: 66 Défis: 0 Message

Citer : Posté le 29/08/2025 12:35 | #


i tried to do the bare minimum for the function to work now it doesn't return an error:
typedef struct {
    int x;
    int y;
}Pos;

void NewTile(int field[4][4])
{
    Pos *FreeP = NULL;
    int FreePItems = 0;
    for(int y=0; y<=3; y++){
        for(int x=0; x<=3; x++){
            if (field[y][x]==0){
                FreePItems++;
                FreeP = krealloc(FreeP, FreePItems*sizeof(Pos));

                FreeP[FreePItems-1].x = x;
                FreeP[FreePItems-1].y = y;
                
                
            }
        }
    }
    kfree(FreeP);
    return;
}

int main(void)
{

    int field[4][4] = {{0,0,0,0},{0,1,0,0},{0,5,0,0},{0,2,1,0}};
    
    NewTile(field);
    getkey();

    return 1;
}
Lephenixnoir En ligne Administrateur Points: 25372 Défis: 174 Message

Citer : Posté le 29/08/2025 12:49 | #


Yeah I'm not super surprised. There must be something else interfering. Make sure you don't have any async problems, like leaky timers. Other than that try to minimize while keeping the bug and that'll give you hints at what's causing it.
Mon graphe (27 Juin): (MQ || Rogue Life) ; serial gint ; passe gint 3 ; Azur ; ...) || (shoutbox v5 ; v5)
Simnon Hors ligne Membre Points: 66 Défis: 0 Message

Citer : Posté le 29/08/2025 16:31 | #


ok this seems to be the minimum example where the bug happens, when i remove the realloc() it works. i also have some images loaded if that matters


typedef struct {
    int x;
    int y;
}Pos;

int rint(int min, int max){
    return (rand()%(max-min+1))+min;
}

/*
void Draw(int field[4][4], bopti_image_t tiles[8]){
    dclear(C_WHITE);

    char num[64];

    for(int y=0; y<=3; y++){
        for(int x=0; x<=3; x++){
            dimage(x*16, y*16, &tiles[field[y][x]]);
        }
    }

    dupdate();
}*/

void NewTile(int field[4][4])
{
    Pos *FreeP = NULL;
    int FreePItems = 0;
    for(int y=0; y<=3; y++){
        for(int x=0; x<=3; x++){
            if (field[y][x]==0){
                FreePItems++;
                FreeP = krealloc(FreeP, FreePItems*sizeof(Pos));
                //FreeP[FreePItems-1].x = x;
                //FreeP[FreePItems-1].y = y;
                
            }
        }
    }
    kfree(FreeP);
    return;
}

int main(void)
{

    
    srand(54);
    dclear(C_WHITE);
    dupdate();

    int field[4][4] = {{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}};
    field[rint(0,3)][rint(0,3)] = 1;
    gint_setrestart(1);
    while(1){
        clearevents();
        
        if(keydown(KEY_MENU)){
            gint_osmenu();
            return 1;
        }

        

        if(keydown_any(KEY_UP,KEY_RIGHT,KEY_LEFT,KEY_DOWN)){
            NewTile(field);
        }

    }
}
Lephenixnoir En ligne Administrateur Points: 25372 Défis: 174 Message

Citer : Posté le 29/08/2025 16:42 | #


Thanks. I'll run it later... from a first read the only suspicious thing is that keydown_any() needs a 0 terminator that it doesn't have.
Mon graphe (27 Juin): (MQ || Rogue Life) ; serial gint ; passe gint 3 ; Azur ; ...) || (shoutbox v5 ; v5)
Simnon Hors ligne Membre Points: 66 Défis: 0 Message

Citer : Posté le 29/08/2025 16:45 | #


ohhh im supposed a 0 at the end?
Simnon Hors ligne Membre Points: 66 Défis: 0 Message

Citer : Posté le 29/08/2025 16:47 | #


it still crashes tho
Simnon Hors ligne Membre Points: 66 Défis: 0 Message

Citer : Posté le 01/09/2025 21:25 | #


i fixed by using a fixed array

LienAjouter une imageAjouter une vidéoAjouter un lien vers un profilAjouter du codeCiterAjouter un spoiler(texte affichable/masquable par un clic)Ajouter une barre de progressionItaliqueGrasSoulignéAfficher du texte barréCentréJustifiéPlus petitPlus grandPlus de smileys !
Cliquez pour épingler Cliquez pour détacher Cliquez pour fermer
Alignement de l'image: Redimensionnement de l'image (en pixel):
Afficher la liste des membres
:bow: :cool: :good: :love: ^^
:omg: :fusil: :aie: :argh: :mdr:
:boulet2: :thx: :champ: :whistle: :bounce:
valider
 :)  ;)  :D  :p
 :lol:  8)  :(  :@
 0_0  :oops:  :grr:  :E
 :O  :sry:  :mmm:  :waza:
 :'(  :here:  ^^  >:)

Σ π θ ± α β γ δ Δ σ λ
Veuillez donner la réponse en chiffre
Vous devez activer le Javascript dans votre navigateur pour pouvoir valider ce formulaire.

Si vous n'avez pas volontairement désactivé cette fonctionnalité de votre navigateur, il s'agit probablement d'un bug : contactez l'équipe de Planète Casio.

Planète Casio v4.3 © créé par Neuronix et Muelsaco 2004 - 2025 | Il y a 71 connectés | Nous contacter | Qui sommes-nous ? | Licences et remerciements

Planète Casio est un site communautaire non affilié à Casio. Toute reproduction de Planète Casio, même partielle, est interdite.
Les programmes et autres publications présentes sur Planète Casio restent la propriété de leurs auteurs et peuvent être soumis à des licences ou copyrights.
CASIO est une marque déposée par CASIO Computer Co., Ltd