In the process of writing a hex editor, I stumbled on a peculiar bug where writes to G3A files frequently fail with various System ERROR or reboots.
I originally thought this was a bug in my kernel, but upon closer inspection I can reproduce it easily on my fx-CG 50 with a simple vanilla/PrizmSDK program, shown below.
All it does is load Conv.g3a from the storage memory then rewrite it 100 times. When writing to a non-G3A file, eg. Conv.bin, it works no problem. But when writing to a G3A file, it always crashes in less than 10 runs. From other testing, I believe writing a G3A file that is obviously an invalid add-in (eg. file smaller than the G3A header) does not trigger the bug.
Archive with G3A file and buildable sources (up to toolchain name I believe): WriteG3A.zip
Obviously it must be related to add-in registration, but I don't know why that would be a problem for the OS.
Any ideas what might be causing the crash?
Code:
I originally thought this was a bug in my kernel, but upon closer inspection I can reproduce it easily on my fx-CG 50 with a simple vanilla/PrizmSDK program, shown below.
All it does is load Conv.g3a from the storage memory then rewrite it 100 times. When writing to a non-G3A file, eg. Conv.bin, it works no problem. But when writing to a G3A file, it always crashes in less than 10 runs. From other testing, I believe writing a G3A file that is obviously an invalid add-in (eg. file smaller than the G3A header) does not trigger the bug.
Archive with G3A file and buildable sources (up to toolchain name I believe): WriteG3A.zip
Obviously it must be related to add-in registration, but I don't know why that would be a problem for the OS.
Any ideas what might be causing the crash?
Code:
#include <fxcg/display.h>
#include <fxcg/keyboard.h>
#include <fxcg/file.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
char *conv_g3a;
#define SIZE 65536
int load(void)
{
int fd = Bfile_OpenFile_OS(u"\\\\fls0\\Conv.g3a", BFILE_READ, 0);
if(fd < 0) return -1;
int rc = Bfile_ReadFile_OS(fd, conv_g3a, SIZE, -1);
Bfile_CloseFile_OS(fd);
return rc;
}
int save(int size)
{
int fd = Bfile_OpenFile_OS(u"\\\\fls0\\Conv.g3a", BFILE_WRITE, 0);
if(fd < 0) return -1;
int rc = Bfile_WriteFile_OS(fd, conv_g3a, size);
Bfile_CloseFile_OS(fd);
return rc;
}
int main(void)
{
conv_g3a = malloc(SIZE);
if(!conv_g3a) return 1;
int size = load();
if(size < 0) return 1;
char str[128];
Bdisp_AllClr_VRAM();
sprintf(str+2, "Loaded %d bytes", size);
PrintXY(1, 1, str, 0, 0);
Bdisp_PutDisp_DD();
for(int i = 1; i <= 100; i++) {
int rc = save(size);
if(rc < 0) return 1;
Bdisp_AllClr_VRAM();
sprintf(str+2, "[%d] Saved %d bytes", i, rc);
PrintXY(1, 1, str, 0, 0);
Bdisp_PutDisp_DD();
}
return 1;
}