Right now I'm trying to see if I can create a file and have it put Sprite data in it, but I keep getting the segfault:

Code:

System ERROR
REBOOT    :[EXIT]
INITIALIZE:[EXE]
 ILLEGAL CODE ERR
 TARGET=00000000
 PC    =00000000


This is my save code:

Code:

void saveFile(char *filename, color_t *data, int width, int height){
    char widthbuffer[sizeof(width)/2], heightbuffer[sizeof(height)/2];
    int size = sizeof(data)+sizeof(width)+sizeof(height);
    char PATH[sizeof("\\\\fls0\\")+strlen1(filename)+sizeof(".ppf")];
    unsigned short pFile[sizeof(PATH)*2];
    strcat(PATH, "\\\\fls0\\");
    strcat(PATH, filename);
    strcat(PATH, ".ppf");
    Bfile_StrToName_ncpy(pFile, (unsigned char*)PATH, sizeof(PATH));
    Bfile_CreateEntry_OS(pFile, CREATEMODE_FILE, &size);
    int hFile = Bfile_OpenFile_OS(pFile, 2);
    itoa(width, widthbuffer);
    PrintXY(1,0,"xxPie1",0,0);
    Bfile_WriteFile_OS(hFile, widthbuffer, sizeof(widthbuffer));
    Bfile_WriteFile_OS(hFile, "\n", sizeof("\n"));
    itoa(height, heightbuffer);
    PrintXY(1,0,"xxPie2",0,0);
    Bfile_WriteFile_OS(hFile, heightbuffer, sizeof(heightbuffer));
    Bfile_WriteFile_OS(hFile, "\n", sizeof("\n"));
    PrintXY(1,0,"xxPie3",0,0);
    Bfile_WriteFile_OS(hFile, data, sizeof(data));
    Bfile_WriteFile_OS(hFile, "\n", sizeof("\n"));
    Bfile_CloseFile_OS(hFile);
}


I put the PrintXY's for debugging purposes, but it doesn't display them so I assume it's something before. Any ideas?

Also, do you see anything with my previous problem above?
Based on the reported error it looks like you're smashing the stack, but I don't feel any inclination to pull apart your code.
I'm trying to resize a sprite and this is the code I'm using:

Code:
    color_t* temp = (color_t*)malloc(sizeof(sprite)*sizeof(color_t));
    sprite = (color_t*)realloc(temp, ((width*height)*2)*sizeof(color_t));
    free(temp);


It's not working correctly. Am I doing this correctly?
What is the issue exactly? Is the data in sprite not the same as in temp?
AHelper wrote:
What is the issue exactly? Is the data in sprite not the same as in temp?


The sprite it returns is all black with some random color in(except for the first pixels which are the same color of the original sprite). Is it supposed to be like this? Also, when i try to do it multiple times, it gives me a segfault(sometimes it freezes too).

Note: I'm not trying to stretch/skew. Just change the size.
Also, for your above code block, the issue may be the itoa(width, widthbuffer); widthbuffer is set to 2 bytes, only one byte if you take into account the '\0'.

Also, you do strcat to an uninitialized character array. Use strcpy for instead of the first strcat.
AHelper wrote:
Also, for your above code block, the issue may be the itoa(width, widthbuffer); widthbuffer is set to 2 bytes, only one byte if you take into account the '\0'.

Also, you do strcat to an uninitialized character array. Use strcpy for instead of the first strcat.


Thanks! It worked! But can someone tell me what's going on with the realloc resizing sprites?
I would blame libfxcg for that. I would need to check the source to see what it is doing.
Looks like you're doing potentially bad things to the heap because you're ignoring the semantics of realloc(). Freeing after realloc()ing is definitely wrong (provided realloc succeeds, you're double-freeing), and when realloc fails (for whatever reason) it returns NULL without changing your allocations.

Further, it appears that sprite is a pointer (since you assign the result of realloc to it), in which case sizeof(sprite) isn't doing what you expect.
Does anyone know how to modify Kerm's input routine to make it have the status bar and display whether or not it has shift mode/alpha mode? Also, how to make it do lowercase?

Edit: Also, is there a way to do line wrapping instead of scrolling?

Edit2: Fixed the lowercase. Woohooo! But can anyone help me with the others?
Do not use Kerm's input routine. Use the OS text input syscalls instead.
What's the difference between them? Could I modify the OS Input to do Print Mini instead, or not? I might just stay with Kerm's.

Edit: Nevermind about the OS. All I need help with right now is word wrapping. I'm working on modifying PrintMiniFix and Kerm's input to do it, but it isn't working correctly at the moment. I'm trying to fix it. If any of you guys have any suggestions for me, it would be appreciated.
*BUMP(it's been almost 24 hours)*

Can someone help me with modifying PrintMiniFix and Kerms input routine to support word wrapping? and scrolling too?
*BUMP*

Can someone help with this^^^^^^
Also, can someone help me with a sprite rotating routine(intervals of 90 degrees please)?
*BUMP*

Okay, I'm trying to use the OS input now, but lowercase alphalock isn't working. The tutorial on the wiki didn't show how to do lowercase, so I used some of gbl08ma's utilities code from his github(from the lock.cpp). Also it isn't putting the symbols immediately(it places them after you type a regular character). This is my input code:


Code:
int TextInput(char *buffer, int x, int y, int statusbar){
    int filesize;
    char filename[256] = "";
    char SaveBuf[50];
    int mode = MODE_TXT;
    int start = 0;
    int cursor = 0;
    int key;
    int iresult;
    char* status;
    DisplayMBString((unsigned char*)buffer, start, cursor, x, y);
    int keyflag = GetSetupSetting( (unsigned int)0x14);
    while(1){
        GetKey(&key);
        GetFKeyPtr(0x03B1, &iresult);
        FKey_Display(0, (int*)iresult);
        GetFKeyPtr(0x03B2, &iresult);
        FKey_Display(1, (int*)iresult);
        GetFKeyPtr(0x0307, &iresult);
        FKey_Display(4, (int*)iresult);
        GetFKeyPtr(0x02A1, &iresult);
        FKey_Display(5, (int*)iresult);
        if(key == KEY_PRGM_F3)
            mode = MODE_TXT;
        if(key == KEY_PRGM_F4)
            mode = MODE_LUA;
        if(mode == MODE_TXT)
            status = "Txt";
        else if(mode == MODE_LUA)
            status = "Lua";
        PrintMiniFix(344, 3, status, 0x40, COLOR_BLACK, COLOR_WHITE);
        if (GetSetupSetting( (unsigned int)0x14) == 0x01 || GetSetupSetting( (unsigned int)0x14) == 0x04 || GetSetupSetting( (unsigned int)0x14) == 0x84) {
            keyflag = GetSetupSetting( (unsigned int)0x14);
        }
      if(key == KEY_CTRL_F1){
            fileBrowser(filename, (unsigned char*)"*.txt", (unsigned char*)"*.lua", (unsigned char*)"*.ppf", "Txt Files");
            if(!strcmp(filename, "")) {
                return 1;
            } else {
                openFile(filename, buffer);
                filesize = getFileSize(filename, filesize);
            }
        }
      if(key == KEY_CTRL_F2){
            InputBox(SaveBuf, "Save", COLOR_BLACK, COLOR_LIGHTGRAY, 50, INPUT_MODE_TEXT);
            saveFile(SaveBuf, buffer, mode);
        }
        if(key == KEY_CTRL_F5)
        {
            if (keyflag == 0x04 || keyflag == 0x08 || keyflag == 0x84 || keyflag == 0x88) {
            // ^only applies if some sort of alpha (not locked) is already on
                if (keyflag == 0x08 || keyflag == 0x88) { //if lowercase
                    SetSetupSetting( (unsigned int)0x14, keyflag-0x04);
                    if (statusbar == 1) DisplayStatusArea();
                        continue; //do not process the key, because otherwise we will leave alpha status
                } else {
                    SetSetupSetting( (unsigned int)0x14, keyflag+0x04);
                    if (statusbar == 1) DisplayStatusArea();
                        continue; //do not process the key, because otherwise we will leave alpha status
                }
            }
        }
        else if(key == KEY_CTRL_F6)
        {
            SaveVRAM_1();
            Bkey_ClrAllFlags();
            short character;
            character = CharacterSelectDialog();
            if (character) cursor = EditMBStringChar((unsigned char*)buffer, 100000, cursor, character);
            LoadVRAM_1();
        }
        if(key && key < 30000){
            if ((keyflag == 0x08 || keyflag == 0x88) && key >= KEY_CHAR_A && key <= KEY_CHAR_Z) //if lowercase and key is char...
            {
                key = key + 32;
            }
            cursor = EditMBStringChar((unsigned char*)buffer, 100000, cursor, key);
            DisplayMBString((unsigned char*)buffer, start, cursor, 1,1);
        }else{
            EditMBStringCtrl((unsigned char*)buffer, 100000, &start, &cursor, &key, 1, 1);
        }

    }
}


Can anyone help?
*BUMP #5*
That's a lot of bumps. Razz

Anyways, can someone help^^^?

Also, if the buffer being edited already has info in it, will it let you edit that info(will it display it)? Because when I try to open a file, it doesn't pop up like it does with Kerm's input routine.
It isn't putting the symbols immediately because you must do the LoadVRAM_1(); before the EditMBStringChar. Otherwise you'll be updating the screen with a new symbol, then loading an old VRAM (without the symbol printed) on top of it.

As for the lowercase problem, I'm yet to look enough into your code to find the problem.
gbl08ma wrote:
It isn't putting the symbols immediately because you must do the LoadVRAM_1(); before the EditMBStringChar. Otherwise you'll be updating the screen with a new symbol, then loading an old VRAM (without the symbol printed) on top of it.

As for the lowercase problem, I'm yet to look enough into your code to find the problem.


Okay. Thanks. If you see the cause of the lowercase problem, be sure to reply. Also, if I have something already in the buffer when I load the program, will it display immediately? I try to open a file it doesn't display anything and when I press the [>] button it fills it with "U"s.
This^^^^^^^^^^^^^^^^^^^

Also, can someone explain animated sprites to me thoroughly? It really confuses me.
*BUMP*
I've started again with that Tunnel program I tried to make a while ago. Restarted porting with the original code. Now I don't understand why it is returning:

Code:
 angle_lut = malloc(w * sizeof(*angle_lut));
 if(!angle_lut) return 0;

 depth_lut = malloc(w * sizeof(*depth_lut));
 if(!depth_lut)
 {
  free(angle_lut);
  return 0;
 }


Apparently, one(or both) of the mallocs are returning null pointers. I don't understand why though. Why is it failing?
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
» Goto page Previous  1, 2, 3 ... , 11, 12, 13  Next
» View previous topic :: View next topic  
Page 12 of 13
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement