Jump to content

Console window crashes when printing while it is hidden


Steffen

Recommended Posts

Hi hi,

as the title suggests i'm using a console widget and get crashes when using gwinPrintf/gwinPutString on it while it is hidden. However this only seems to happen when the console was completely filled previously. I tested it with µGFX 2.8 as well as the current git master (though thats just one commit ahead of the tag).

To reproduce it more easily i took the gwin/console demo and modified it for the purpose. The Attached archive includes the modified demo and a Makefile for Linux X11, though by adapting the Makefile this should work on any platform. To reproduce it just unpack the archive, then copy/clone µGFX into the new directory or alternatively change GFXDIR in the Makefile. Then run make to compile.

I captured the following information from the crash with gdb:

(gdb) r
Starting program: /tmp/crash_example/.build/crash_example 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Running GFX Window in 24 bit color
[New Thread 0xf7c2bb40 (LWP 18352)]
[New Thread 0xf72ffb40 (LWP 18353)]

Thread 1 "crash_example" received signal SIGSEGV, Segmentation fault.
0xf7dae379 in ?? () from /lib/i386-linux-gnu/libc.so.6
(gdb) bt
#0  0xf7dae379 in ?? () from /lib/i386-linux-gnu/libc.so.6
#1  0x56559016 in scrollBuffer.lto_priv.15 (gcw=0x56568450) at uGFX//src/gwin/gwin_console.c:191
#2  0x56556a1b in gwinPutChar (gh=0x56568450, c=53 '5') at uGFX//src/gwin/gwin_console.c:548
#3  0x5655735d in gwinPrintf (gh=0x56568450, fmt=0x565608ba "\n") at uGFX//src/gwin/gwin_console.c:823
#4  0x56557fe4 in main () at uGFX//../console_crash/main.c:76
(gdb) frame 1
#1  0x56559016 in scrollBuffer.lto_priv.15 (gcw=0x56568450) at uGFX//src/gwin/gwin_console.c:191
191				memcpy(gcw->buffer, p, gcw->bufpos);	// Move the rest of the data
(gdb) print gcw->bufpos
$1 = 4294967295
(gdb) print dp
$2 = 2
(gdb) print gcw->buffer
$3 = 0x56575450 "\n42\n41\n40\n49\n3\n38\n37\n36\n3\n35\n433\n34\n3\n34\n333\n2\n3\n30\n31\n\n3\n\n626\n27\n\n2\n\n24\n2\n2\n17\n18\n19\n8\n17\n16\n15\n14\n13\n12\n11\n10\n19\n\n\n\n\n\n\n\n"
(gdb) print p
$4 = 0x56575452 "2\n41\n40\n49\n3\n38\n37\n36\n3\n35\n433\n34\n3\n34\n333\n2\n3\n30\n31\n\n3\n\n626\n27\n\n2\n\n24\n2\n2\n17\n18\n19\n8\n17\n16\n15\n14\n13\n12\n11\n10\n19\n\n\n\n\n\n\n\n"
(gdb) print gcw->bufsize
$5 = 4601

Seems bufpos is slightly off there. Am i using the widget wrong or is this an actual bug?

In my actual code i for now worked around this by stalling the print calls until the console becomes visible. Though when the console is filled and i hide it then it will be emptied once i set it visible again, only the newly added lines will appear at the top rather than being appended to the old content. Not sure if that is intended or possibly related (GDISP_NEED_SCROLL is disabled but the buffer should handle it i guess?).

crash_example.tar.gz

Link to comment
Share on other sites

On 12/21/2017 at 08:51, Steffen said:

In my actual code i for now worked around this by stalling the print calls until the console becomes visible. Though when the console is filled and i hide it then it will be emptied once i set it visible again, only the newly added lines will appear at the top rather than being appended to the old content. Not sure if that is intended or possibly related (GDISP_NEED_SCROLL is disabled but the buffer should handle it i guess?).

The answer to your question is in the wiki. The console does not keep track of it's history and will be emptied when set invisible. You need GWIN_CONSOLE_USE_HISTORY for console history.

I have no idea why your application crashes...

Link to comment
Share on other sites

This might be a problem with the amount of memory allocated for the history buffer. There is a configuration variable that changes how memory is allocated. In one case it will allocate enough memory to cover the entire window, in the other case it allocated a proportion of that based on a fill percentage for the window given that windows seldom are 100% full of characters.

Note that this calculation is done when the window is created. If you change the window font to a smaller font then the memory allocated may be insufficient for a full screen.

In any case, the buffer not being large enough will not cause crashes. It will just forget earlier data (contents at the top of the window).

 

Link to comment
Share on other sites

  • 3 weeks later...

I suppose you are refering to GWIN_CONSOLE_HISTORY_AVERAGING? I do not have this defined so the buffer should be allocated for the entire window. There are no font or size changes after creating the console window, only its visibility is changed.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...