Posté le 29/08/2025 12:12
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
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.
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
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:
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;
}
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.
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);
}
}
}
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.
Citer : Posté le 29/08/2025 16:45 | #
ohhh im supposed a 0 at the end?
Citer : Posté le 29/08/2025 16:47 | #
it still crashes tho
Citer : Posté le 01/09/2025 21:25 | #
i fixed by using a fixed array