You are not logged in.

#1 2010-09-10 13:25:57

chatuser
Member

Text corruption during runtime

I'll try to explain this problem using my poor English:

I have implemented a console to display a log of communication messages. I erase the screen using this function:

Code:

void Console::clearScreen() {

    if (!consoleMode)
        return;

    mutexLock();

    GRRLIB_FillScreen(GRRLIB_NAVY);
    GRRLIB_PrintfTTF(console_minimum_x,console_minimum_y,myFont,"press B button to exit from console mode ",getFontSize(),GRRLIB_YELLOW);
    xConsola = console_minimum_x;
    yConsola = console_minimum_y+getFontSize()+1;
    GRRLIB_Screen2Texture(0,0,copyConsole,false);

    setRender(true);
    mutexUnlock();
}

And I write on the screen usign this function:

Code:

void Console::print(const char* str,const u32 color) {

    if (!consoleMode)
        return;

    mutexLock();

    // restore previous screen
    GRRLIB_DrawImg(0,0,copyConsole,0,1,1,GRRLIB_WHITE);

    char str[200];
    strncpy(str,str,200);
    unsigned previous = 0;
    for (unsigned i=0; i<strlen(str); i++)
        if (str[i]=='\n') {
            str[i] = '\0';
            GRRLIB_PrintfTTF(xConsole,yConsole,myFont,str+previous,getFontSize(),color);
            previous = i+1;
            xConsole=Console_minimum_x;
            yConsole+=getFontSize()+1;
        }

    if (strlen(str) != previous) {
        GRRLIB_PrintfTTF(xConsole,yConsole,myFont,str+previous,getFontSize(),color);
        // ignore multiline strings
        xConsole+=GRRLIB_WidthTTF(getFont(),str+previous,getFontSize());
        if (xConsole>=(unsigned)rmode->fbWidth-50) {
            xConsole=Console_minimum_x;
            yConsole+=getFontSize()+1;
        }
    }

    // clear screen instead scrolling
    if (yConsole>=rmode->xfbHeight)
        //yConsole=Console_minimum_y+getFontSize()+1;
        clearScreen();

    // copy screen content
    GRRLIB_Screen2Texture(0,0,copyConsole,false);

    setRender(true);
    mutexUnlock();
}

Well, a communications thread uses these functions to write text on the screen and if console mode is cancelled then the main() function takes the control of the screen. Mutexes are used to let main() function call to GRRLIB_Render() when something is waiting to be displayed on the screen.

The problem is that after every GRRLIB_DrawImg() call the text on the screen gets corrupted, even the background of color GRRLIB_NAVY gets darker, and the text on the top of the screen is more corrupted that in the middle, the last displayed text is almost perfect.

I have no idea about what happens, thanks in advance.

Offline

 

#2 2010-09-10 14:12:37

NoNameNo
Administrator

Re: Text corruption during runtime

hi,

i bet your GRRLIB_Settings.antialias is true  try setting it to false, and tell me.

NNN

Offline

 

#3 2010-09-10 16:32:52

chatuser
Member

Re: Text corruption during runtime

The problem continues using this code:

Code:

    GRRLIB_Init();
    GRRLIB_SetAntiAliasing(false);

Is there any way to change this setting ?

Last edited by chatuser (2010-09-10 16:33:48)

Offline

 

#4 2010-09-10 19:22:57

chatuser
Member

Re: Text corruption during runtime

This is a screenshot showing the problem:

http://i51.tinypic.com/2evt545.png

The image gets more corrupted every time GRRLIB_Render() is called.

Last edited by chatuser (2010-09-10 20:03:01)

Offline

 

#5 2010-09-11 22:12:56

chatuser
Member

Re: Text corruption during runtime

Don't ask me how, I have changed the order of some GRRLIB functions calls and now it works as expected, I think there is some "magical" combination of operations that causes this problem, but now it has been solved.

Offline

 

#6 2010-09-12 00:34:27

Crayon
Bad Mother Fucker

Re: Text corruption during runtime

chatuser wrote:

Don't ask me how, I have changed the order of some GRRLIB functions calls and now it works as expected, I think there is some "magical" combination of operations that causes this problem, but now it has been solved.

If it's possible we would appreciate to see your modifications. Thanks.

Offline

 

#7 2010-09-14 12:14:29

chatuser
Member

Re: Text corruption during runtime

Sorry for answering late, I have reordered and simplified the code, but after of tons of tests I can't say what exactly solved the problem.

I have removed the mutexes and reduced the number of GRRLIB_Render() calls, I suspect that mutexes and interlaced GRRLIB_Render() calls fouled up the program logic.

Offline

 

Board footer

Powered by FluxBB