Recent

Author Topic: Application crashing after closing  (Read 3810 times)

bobkos

  • New Member
  • *
  • Posts: 32
    • Personal Finance Manager
Application crashing after closing
« on: December 20, 2017, 06:17:57 am »
Dear Colleagues,

First of all sorry fo my english, it is not my native language.

So the point is that after upgrade to Lazarus 1.8.0 x64 (Windows 10 x64), my application compiling, but crashing on close. I don't know how to explaim more in details and can't catch the problem so far, so let me show you small video (https://youtu.be/EWfT9IEMqIw) and may be someone can help me. I don't understand what happening since nothing has changed in source code.

Thank you in advance.

Handoko

  • Hero Member
  • *****
  • Posts: 4348
  • My goal: build my own game engine using Lazarus
Re: Application crashing after closing
« Reply #1 on: December 20, 2017, 09:06:58 am »
Hello friend,

I watched your video and I saw your code already has memory issue when running using the binary compiled using Lazarus 1.6.4. Memory issues sometimes may cause program to crash but sometimes they don't. So I think the crash is not caused by upgrading to Lazarus 1.8.0.

howardpc

  • Hero Member
  • *****
  • Posts: 3786
Re: Application crashing after closing
« Reply #2 on: December 20, 2017, 09:33:55 am »
No. The "Error" caption for heaptrc's window is itself an error in this case. You can see that the reported data show no orphaned memory ranges.

The only reliable way for bobkos to get help with debugging his project would be for him to provide compilable code that shows the problem.

Thaddy

  • Hero Member
  • *****
  • Posts: 10929
Re: Application crashing after closing
« Reply #3 on: December 20, 2017, 12:14:30 pm »
Indeed, the heaptrace reports no errors.
It is an external sigsev. That may be related to your GDB version. I experienced a similar problem on one of my machines.
It may also be from an external library.

Does the application crash without debug info? in release mode? If it does not, upgrade your GDB version.
« Last Edit: December 20, 2017, 12:26:15 pm by Thaddy »
The average programmer productivity is 4-5 hours per day. Peak performance 72 hours for short bursts. MTBF is 1 second or less.

taazz

  • Hero Member
  • *****
  • Posts: 5364
Re: Application crashing after closing
« Reply #4 on: December 20, 2017, 01:50:03 pm »
use your stack trace window to find which runtime component produces the problem, check for onclose event handlers. The code break happens in the TDataset.Close method in the DB unit which should not have any external calls other than closing any active cursor. Try to set active:=false on your datasets (or connected := false on your connection object) before exiting and see if that helps at all.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

bobkos

  • New Member
  • *
  • Posts: 32
    • Personal Finance Manager
Re: Application crashing after closing
« Reply #5 on: December 20, 2017, 02:26:25 pm »
Thanks for yours!

Yes, application also crashing without debugging info (release mode).
Also I'm using SQLite as an external library, that's it.
So as I said, nothing changing in the code, but after compiling in 1.8.0 I've got error.

The problem is I don't know exactly which part of code caused the error itself, furthermore I've tried to empty all events, i.e. OnCreate, OnShow, OnClose and OnDestroy (my thought was that problem is on closing events), but nothing helps... And yes, the stack trace window shows that the problem is in TDataSet, but DB is not open at all. Let me show you one more video https://youtu.be/d9ueRTakTDw

Maybe you have some ideas, how to identify the exact part of code which cause error?

rvk

  • Hero Member
  • *****
  • Posts: 4482
Re: Application crashing after closing
« Reply #6 on: December 20, 2017, 02:38:44 pm »
You have a few other unit I see in your project. (like uLicense, uSyncServer, uStrRes etc.)
You should check those too for anything they do during finalization.

Somehow it looks like there is a close done on a TDataset which is never created.
(i.e. pointer to a dataset-variable is null)

What do you have in FormCreate, FormShow, FormClose and FormDestroy?
You now have leaks when you remove those. That shouldn't happen either.
When you create something in FormCreate you can free it in FormDestroy.
But somehow you are creating something somewhere else too.

Without showing some of the code it's very difficult to pinpoint your problem.

bobkos

  • New Member
  • *
  • Posts: 32
    • Personal Finance Manager
Re: Application crashing after closing
« Reply #7 on: December 20, 2017, 03:48:37 pm »
So ok, thanks for yours suggentions it seems that I've found the problem. Since I'm actively using TNotebook, and its onBeforeShow to prepare some data, found that this event also happening during close of application. I've add some flag "GoingToFinish to true" to OnCloseQuery and put if GoingToFinish the exit; to onBeforeShow procedures, and now the application closing correctly. However my question is what was principialy changed in 1.8.0 comparing to 1.6.4 that's causing the errors on the same code? It's still unclear for me.
« Last Edit: December 20, 2017, 04:29:22 pm by bobkos »

taazz

  • Hero Member
  • *****
  • Posts: 5364
Re: Application crashing after closing
« Reply #8 on: December 20, 2017, 03:55:59 pm »
So ok, thanks for yours suggentions it seems that I've found the problem. Since I'm actively using TPageControl, and its onBeforeShow to prepare some data, found that this event also happening during close of application. I've add some flag "GoingToFinish to true" to OnCloseQuery and put if GoingToFinish the exit; to onBeforeShow procedures, and now the application closing correctly. However my question is what was principialy changed in 1.8.0 comparing to 1.6.4 that's causing the errors on the same code? It's still unclear for me.
You have found a reproducible case. Create a small sample application that shows the error and post it here (or attach it on a bug report on the bug tracker) so more experienced developers with the components might take a look and explain the behavior.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

bobkos

  • New Member
  • *
  • Posts: 32
    • Personal Finance Manager
Re: Application crashing after closing
« Reply #9 on: December 20, 2017, 04:42:35 pm »
I made sample application and attach it here. If some one can explain it will be perfect. As I said earlier I'm using TNotebook (onBeforeShow) to prepare some data, but after closing of application it gaves errors. The situation is as follow, you are closing application but the events onBeforeShow will happening for all pages you have except active page even AFTER FormDestroy.

rvk

  • Hero Member
  • *****
  • Posts: 4482
Re: Application crashing after closing
« Reply #10 on: December 20, 2017, 05:19:19 pm »
Yes, something changed between 1.6.4 and 1.8. It's the way pages are deleted from the notebook.

It can be argued that it behaves correctly now. When you destroy the TNotebook, Page3 is deleted and Page2 should be shown. When Page2 is deleted then Page1 should be shown.

Of course the TPage.Destroy procedure could check if the Parent is in destroy state and just remove itself without activating the next available page.

This was introduced:
Quote
Revision: 53267
Author: juha
Date: zondag 30 oktober 2016 19:16:52
Message: IDEIntf: Add a functional TNoteBook.Pages property editor. Issue #30710, patch from Michl.

It checks if "if (Parent <> nil) and (Parent is TNotebook) then"
But maybe the check for destroying could be done there too.

I've submitted it:
https://bugs.freepascal.org/view.php?id=32863

bobkos

  • New Member
  • *
  • Posts: 32
    • Personal Finance Manager
Re: Application crashing after closing
« Reply #11 on: December 20, 2017, 05:36:53 pm »
Thanks to all for help!

rvk

  • Hero Member
  • *****
  • Posts: 4482
Re: Application crashing after closing
« Reply #12 on: December 20, 2017, 05:41:18 pm »
Maybe until the time you have a fixed version you can do this:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Page2BeforeShow(ASender: TObject; ANewPage: TPage;
  2.   ANewIndex: Integer);
  3. begin
  4.   if (csDestroying in Notebook1.ComponentState) then exit;
  5.   ShowMessage('page2');
  6. end;

Put the highlighted line in every OnBeforeShow-procedure.

Or even this (that way the notebook-variable is taken from ASender):
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Page2BeforeShow(ASender: TObject; ANewPage: TPage;
  2.   ANewIndex: Integer);
  3. begin
  4.   if (ASender is TNotebook) and (csDestroying in (ASender as TNotebook).ComponentState) then exit;
  5.   ShowMessage('page2');
  6. end;

At least this way you don't need to use a "dummy"-variable.
« Last Edit: December 20, 2017, 05:44:52 pm by rvk »

bobkos

  • New Member
  • *
  • Posts: 32
    • Personal Finance Manager
Re: Application crashing after closing
« Reply #13 on: December 20, 2017, 06:42:12 pm »

Put the highlighted line in every OnBeforeShow-procedure.


I appreciate your advice, it's much more elegant solution. :)

 

TinyPortal © 2005-2018