-
Notifications
You must be signed in to change notification settings - Fork 35
CodeSnip crashes after resume from hibernation #70
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
This is a long standing, intractable bug. Dunno why it didn't make it into issues until now. I suspect it's something to do with the web browser control, but haven't confirmed it. (❌😊 probably not see #70 (comment)) |
Just tried 5 hibernations with CodeSnip running from the Delphi XE debugger and stand-alone and not a single crash. |
Crash happened today while debugging. A stack trace indicates that that exception is a fault reading a zero pointer in the Overview pane. The culprit would appear to be an I think I'd never selected anything in the Overview pane before the crash, which could explain the null pointer exception. |
Had another crash under the debugger. Crash is reported as occurring in line
Stack trace is (method followed by indented line in method, where available), with method raising exception listed at top:
|
It seems that the problem is that, sometimes (not always) Windows recreates the tree view displayed in the overview pane and all its nodes. The tree view nodes are custom classes that have a property that reference an This explains the nil The solution used in the fix is to handle the Windows messages sent when the computer hibernates and resumes. On hibernation the state of the tree view is recorded. On restoration we assume that the tree view is corrupted and so forcibly rebuild it and restore the saved state. There is a problem thought. The message we handle is issued twice after resuming from hibernation. There is no easy way to tell which message has been issued. Therefore the tree view is rebuilt twice. There is not much performance penalty to this, so we can let it go. The potential problem is that if the tree view is recreated it happens after the 1st message and before the 2nd. Should, for example, the message only be triggered once then the bug will be back! Even after all this it is possible that the program will redraw the tree view before the All in all, I've not totally happy with this solution, which is more of a work around than a fix, but it's the best I can come up with without completely revising the overview frame code. This fix was implemented at commit 58be37c. |
To replicate I can force this by closing and opening the lid of my laptop, then hibernating it and restoring using the power button. This is strange because closing the lid is configured to do nothing! |
Following a discussion in the comments the DelphiDabbler Blog post at https://tinyurl.com/mrp76mdy it seems that was not a good idea to rely upon handling WM_POWERBROADCAST's PBT_APMPOWERSTATUSCHANGE event to restore the overview pane's tree view nodes to the expected state after Windows has recreated the tree view in an invalid state. So I've modified the code to only rely on the PBT_APMSUSPEND event of WM_POWERBROADCAST and not PBT_APMPOWERSTATUSCHANGE. PBT_APMSUSPEND is handled to prepare for hibernation by not only saving the tree view's state (as per the previous fix) but also setting an event handler that gets called only when the tree view's window gets recreated by Windows AND the treeview contains nodes with nil IView pointers. When called, the event handler rebuilds the tree view with nodes containing valid IView references. The problem is that the event needs to be triggered from the TTreeView.CreateWnd method that gets called when Windows recreates the tree view. Since TTreeView exposes no suitable events, the only way is to inject a suitable event using a nasty hack. Not good practise. Note that all the methods that depend on the hack have been given names beginning with "_HACK_" to make it obvious where the naughtiness lies.
When CodeSnip is running and Windows is hibernated and resumed CodeSnip crashes with an unrecoverable exception.
Selecting "Terminate" sometimes results in an endless loop and the process has to be killed with task manager.
The text was updated successfully, but these errors were encountered: