GnuCash
Contact   Instructions
Bug 797186 - gtk crash closing parent window edit->stylesheets
Summary: gtk crash closing parent window edit->stylesheets
Status: RESOLVED FIXED
Alias: None
Product: GnuCash
Classification: Unclassified
Component: User Interface General (show other bugs)
Version: git-maint
Hardware: PC All
: Normal normal
Target Milestone: ---
Assignee: ui
QA Contact: ui
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-04-09 11:17 EDT by Christopher Lam
Modified: 2019-05-09 20:33 EDT (History)
4 users (show)

See Also:


Attachments

Description Christopher Lam 2019-04-09 11:17:53 EDT
A simple bug. Probably parent_window issues.

I can't fix it. If I follow this bug I can learn fix it.

Steps:
Edit -> Style Sheets
Select any stylesheet - opens "Select HTML Style Sheet" window
Press Edit - opens "Edit HTML Style Sheet Properties" window
Move Stylesheet Edit window away
Press Close on the "Select HTML Style Sheet" window

Expected:
(maybe) "Select HTML Style Sheet" closes, stylesheet edit window remains.

Actual:
segfault

This is more visible on v3.5 on Windows whereby, for some reason, the Edit-stylesheet window stays on top of the "Edit HTML Style Sheet Properties" window, and I try close the edit-stylesheet window, and it freezes.
Comment 1 John Ralls 2019-04-09 12:24:55 EDT
The first step is to get a stack trace. See https://wiki.gnucash.org/wiki/Stack_Trace if you don't know how. You'll need to have built GnuCash with -DCMAKE_BUILD_TYPE=Debug in order to get the stack trace to show you the line where it crashed.

The crash is at https://github.com/Gnucash/gnucash/blob/maint/gnucash/report/report-gnome/dialog-report-style-sheet.c#L134 from dereferencing "ss". Notice two lines above that ss is a copy of the file-global variable gnc_style_sheet_dialog, and apparently that has either not gotten set, set wrong, or cleared so that it points outside of the programs memory segment (that's what "segfault" or "segmentation fault" means: the program tried to access memory that it's not allowed to), most commonly address 0x0, aka NULL or in C++ nullptr.

Now look at stack trace frame 16: It's https://github.com/Gnucash/gnucash/blob/maint/gnucash/report/report-gnome/dialog-report-style-sheet.c#L394. The line above it is "gnc_style_sheet_dialog = NULL". Oops.

So the fix should indeed be pretty simple: Switch lines 393 and 394 so that the gnc_style_sheet_options_close_cb can find the dialog it's supposed to close.
Comment 2 Christopher Lam 2019-04-10 03:51:31 EDT
(This wouldn't have happened with scheme :evil_grin: which fails more spectacularly to start with)

My query is why crash now; wouldn't the source be an invalid parent_window somewhere? On Windows the select-stylesheet *does* remain focussed on top of the child edit-stylesheet window.

From edit-stylesheet, click a colour box to launch edit-color, and close the parent edit-stylesheet works well - both edit-stylesheet and edit-color close down uneventfully.

Wouldn't a proper fix fix both?
Comment 3 John Ralls 2019-04-10 10:46:07 EDT
No, the question is why it doesn't crash when the child window is closed. This crash is because of the way pointers work: They're memory locations that contain the address of something, so the C notation ss->list_store means "look in ss for an address of a structure StyleSheet structure and return the contents of the list_store element of that structure. But ss contains 0x0 because that's what it was set to in line 393. That bit of code must not execute if there's no edit dialog open because it doesn't crash in that case, but I haven't analyzed why.

I'm not sure that Windows even allows non-modal dialog boxes, but it would seem that in this case the Edit dialog is modal on Windows where it isn't on Unix. Since you can't close the Selection dialog with the Edit dialog open you can't trigger the crash.

Note You need to log in before you can comment on or make changes to this bug.