SIGSEGV on Create lazarus / 21-General ---------------------------------------------------------------------- superc · 2021-05-28 08:33 Hello, I am trying to fix the code of a software not made by me, and I receive a very strange SIGSEGV randomly, on Create method: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  F: TMonitorForm;begin  try    try      F := TMonitorForm.Create(nil);    F.WindowState:=wsMaximized;      F.LoadMonitorDataFromDB(MonitorID,ProductCode,ProductLang);      F.SetInDesignMode(True);       if F.ShowModal = mrOK then      begin      self.LoadMonitorDataFromDB(MonitorID,ProductCode, ProductLang);    end;     finally      F.Free;    end;   except    on e: Exception do    begin      MessageDlg('Error xyx...'+e.Message,mtError,[mbOK],0);    end;  end;   sometimes when I debug on line of TMonitorForm.Create(nil) I receive SIGSEGV; once this error pops up, I will always get the same error and have to close the program.... I just can't understand how this is possible, thank you in advance ---------------------------------------------------------------------- dseligo · 2021-05-28 09:27 Quote from: superc on May 28, 2021, 10:33:35 amI am trying to fix the code of a software not made by me, and I receive a very strange SIGSEGV randomly, on Create method: So, you get an error in line 6 of code snippet you sent? What do you have in OnCreate method of form? Quote from: superc [bsometimes [/b]when I debug on line of TMonitorForm.Create(nil) I receive SIGSEGV; You only get error when you are in debug mode (and only then sometimes)? And if you comment out rest of the code (except ShowModal)? Oh, and I usually put create code in front of try .. finally block, like that: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i try  F := TMonitorForm.Create(nil);  try  ...  finally    F.Free;  end;except  on e: Exception do  begin    MessageDlg('Error xyx...'+e.Message,mtError,[mbOK],0);  end;end; ---------------------------------------------------------------------- superc · 2021-05-28 09:30 Quote from: dseligo on May 28, 2021, 11:27:03 amQuote from: superc on May 28, 2021, 10:33:35 amI am trying to fix the code of a software not made by me, and I receive a very strange SIGSEGV randomly, on Create method: So, you get an error in line 6 of code snippet you sent? What do you have in OnCreate method of form? Quote from: superc [bsometimes [/b]when I debug on line of TMonitorForm.Create(nil) I receive SIGSEGV; You only get error when you are in debug mode (and only then sometimes)? And if you comment out rest of the code (except ShowModal)? Oh, and I usually put create code in front of try .. finally block, like that: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i try  F := TMonitorForm.Create(nil);  try  ...  finally    F.Free;  end;except  on e: Exception do  begin    MessageDlg('Error xyx...'+e.Message,mtError,[mbOK],0);  end;end; hello, I receive error before enter on create method, infact i put breakpoint at line 6 and in the first line of create method... ---------------------------------------------------------------------- howardpc · 2021-05-28 10:07 You need to give compilable code that shows the problem if you want better than others' guesses at the cause. ---------------------------------------------------------------------- superc · 2021-05-31 06:25 Quote from: howardpc on May 28, 2021, 12:07:57 pmYou need to give compilable code that shows the problem if you want better than others' guesses at the cause. Hello, unfortunately it remains difficult for me to post something: the project is very large and needs its hardware to work and I can't make a test program to repeat the error. ---------------------------------------------------------------------- egsuh · 2021-05-31 07:17 No problem within TMonitorForm itself? For example, duplicated creation of frames within it, etc.  Or problem with DB connection if it uses DB connection. ---------------------------------------------------------------------- dbannon · 2021-05-31 07:22 > Hello, unfortunately it remains difficult for me to post something: the project is very large and needs its hardware to work and I can't make a test program to repeat the error. That makes it hard. If the crash only happens occasionally its very slow process stepping through code to isolate the spot it happens.  If you are running Linux, you can put a number of writeln() in to help you zero in on the bug, its a lot quicker if you need to run the app again and again hoping for a crash. You can do the same with Windows but use debugln() ("use lazlogger") and direct that output to a file, slower but still the best way, IMHO, to trackdown a random bug. Davo ---------------------------------------------------------------------- Zvoni · 2021-05-31 07:47 What i don't understand: He has var F of Type TMonitorForm He creates it In Line 8 he Loads stuff from a DB In Line 11 he calls F to show modally, which should stop code execution there for the unit we are currently in After modal F has received response OK ---> In Line 13 he loads the same stuff from a DB for "self" --> In which unit are we? by this code "self" should be of type TMonitorForm (or inherited from it). Is he assigning F twice? ---------------------------------------------------------------------- superc · 2021-05-31 09:24 Quote from: Zvoni on May 31, 2021, 09:47:16 amWhat i don't understand: He has var F of Type TMonitorForm He creates it In Line 8 he Loads stuff from a DB In Line 11 he calls F to show modally, which should stop code execution there for the unit we are currently in After modal F has received response OK ---> In Line 13 he loads the same stuff from a DB for "self" --> In which unit are we? by this code "self" should be of type TMonitorForm (or inherited from it). Is he assigning F twice? It's not my code but I understand what you mean: TMonitorForm is already instanciaded and with this function create new form TMonitorForm and passign throut LoadMonitorDataFromDB data; after close in showmodal the main form reload this modify; after this F is destroyed. Self is of TMonitorForm which launches the create of F. ---------------------------------------------------------------------- jamie · 2021-05-31 10:54 I am having a little trouble following this thread. I know you are trying your best to explain it and it's much appreciated because all problems presented does not always mean its only your problem because It could be something else lurking that effects others in their daily attempts of writing code.   From your last post I gather now, that you launched or created a new instance of the same TMonitorForm within a currently running instance of a TmonitorForm, is this correct ?   It the above assessment is correct on my part, which I don't always get correct, I would venture to guess you could be creating a recursive loop.   This is only guess on my part but if I understand your statement of Creating a new instance of the same TMonitorForm from within an existing instance then why? ---------------------------------------------------------------------- superc · 2021-05-31 13:38 Quote from: jamie on May 31, 2021, 12:54:02 pm  From your last post I gather now, that you launched or created a new instance of the same TMonitorForm within a currently running instance of a TmonitorForm, is this correct ?   It the above assessment is correct on my part, which I don't always get correct, I would venture to guess you could be creating a recursive loop.   This is only guess on my part but if I understand your statement of Creating a new instance of the same TMonitorForm from within an existing instance then why? Hello, I'm sorry because I realize that sometimes I'm not entirely clear and thank you for your patience.... however yes, inside a TMonitorForm instance another TMonitorForm instance is created, initialized with different parameters, but, an all this create access violation on create, in a random way? ---------------------------------------------------------------------- egsuh · 2021-06-04 01:32 If you are calling TMonitorForm recursively, there is possibility that caller form could have been freed somewhere else before entering this routine. So this code should not be executed, but because of the recursive call, it is still executed.  Or the reverse may be true. Calling this routine from un-instantiated object. Try inserting ShowMessage etc.,  before F := TMonitorForm.Create.  If the SIGSEGV error occurs at the shoemessage statement then there's higher probability of calling form's non-existence. ---------------------------------------------------------------------- Seenkao · 2021-06-04 05:17 Добрый день! Отключите отладчик. И проверяйте без него. Возможно отладочная информация вносит свои изменения. Так же отключите отладочные флаги! Они действуют и при отключенной отладке. google translate: Good day! Disable the debugger. And check without it. Perhaps the debug information is making its own changes. Also disable debug flags! They also work when debugging is disabled.