[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Crash when restoring screen
From: |
Thomas Dickey |
Subject: |
Re: Crash when restoring screen |
Date: |
Mon, 18 Oct 2021 19:23:23 -0400 |
User-agent: |
Mutt/1.10.1 (2018-07-13) |
On Mon, Oct 18, 2021 at 05:33:23AM +0000, Frank Tkalcevic wrote:
> I’m porting an application from Solaris/curses to Linux/ncurses.
>
> The applications uses scr_dump() and scr_restore() a lot when popping up
> boxes, or launching child applications.
>
> If the terminal is made bigger by the user between the scr_dump() and
> scr_restore(), the application will crash in the ncurses library – sometimes
(I can reproduce this, have a fix)
I don't suppose this case ever worked, since even before my rewrite a few
years ago, ncurses always read into the same window size for restore as
the dump. The getch() does the internal screen-sizing as a side-effect.
> it displays rubbish in the extended area then crashes. It works fine on
> Solaris/curses. I’m using xterm and teraterm.
"fine" is relative: Solaris curses won't detect the screen size-change,
so it'll continue using the same dimensions. In some cases (particularly
if shrinking the screen), you'll get odd repainting due to wrapping.
ncurses won't wrap.
Solaris curses would "see" the size-change if you put an endwin between
the two parts (just before the getch loop). However (reading the source
code in illumos-gate), it seems that if it does notice the size-change,
the getwin/scr_restore will return an error:
/* if get here, everything is ok, read the curscr image */
if (((win = getwin(filep)) == NULL) ||
((type == 2) && ((win1 = dupwin(win)) == NULL)) ||
(win->_maxy != curscr->_maxy) || (win->_maxx != curscr->_maxx) ||
/* soft labels */
(fread((char *)&magic, sizeof (int), 1, filep) != 1))
goto err;
> Sample…
>
>
> #include <ncurses.h>
>
>
> void
> main(int argc, char *argv[] )
> {
> WINDOW *win = initscr();
>
> erase();
> mvprintw(3, 10, "This is the main screen.");
>
> const char *filename = "scr_dump.dmp";
> scr_dump(filename);
>
> erase();
> mvprintw(5, 10, "Make the screen bigger, then press a to continue");
>
> while ( getch() != 'a' )
> continue;
>
> scr_restore(filename);
> doupdate();
>
> mvprintw(8,10,"Press a to exit");
> while ( getch() != 'a' )
> continue;
>
> endwin();
> }
>
>
>
>
>
>
> Frank Tkalcevic
> Senior Software Engineer
> T +61 3 8610 2480
>
> Level 25, 333 Collins Street, Melbourne VIC 3000, Australia
> Website<https://www.latrobefinancial.com.au> |
> LinkedIn<https://au.linkedin.com/company/la-trobe-financial> |
> Facebook<https://www.facebook.com/LaTrobeFinancial/> |
> Blackstone<https://www.blackstone.com/>
> [cid:imagefd1d3b.PNG@eae56563.4eb6d67a]<https://www.latrobefinancial.com.au/>
> Disclaimer<https://www.latrobefinancial.com.au/Home/EmailDisclaimer> |
> Privacy Policy<https://www.latrobefinancial.com.au/Home/PrivacyPolicy>
>
>
>
--
Thomas E. Dickey <dickey@invisible-island.net>
https://invisible-island.net
ftp://ftp.invisible-island.net
signature.asc
Description: PGP signature