rchastain / eschecs

UCI chess GUI
GNU Lesser General Public License v2.1
37 stars 9 forks source link

Replaced all DEBUG wit OPT_DEBUG. Fixed sound files loader. #16

Closed fredvs closed 6 years ago

fredvs commented 6 years ago

PS: There is still a memory leak. Sorry but I did not search/fix it.

rchastain commented 6 years ago

Thank you Fred.

rchastain commented 6 years ago

Hello Fred! You have made a very clean work. 👍

I moved the INI file to the config/ directory.

Not yet found the memory leak. I don't see a call trace with lines and function names as previously. I just see that there is a difference between "true heap size" and "true free heap". But does it really mean that there is a memory leak? Anyway, I will continue to search.

Don't you think that the project is ready for a release?

fredvs commented 6 years ago

Hello Roland.

Here, compiled with -ghl and without -dOPT_SOUND run from console, the message when Eschecs is closed:

Heap dump by heaptrc unit
9172 memory blocks allocated : 8529747/8550232
9171 memory blocks freed     : 8529713/8550192
1 unfreed memory blocks : 34
True heap size : 425984
True free heap : 425792
Should be : 425816
Call trace for block $00007FFFF7FE2D00 size 34
  $00000000004043B2 line 350 of eschecs.pas
  $00000000004C3731 line 438 of ../libraries/fpgui/src/gui/fpg_form.pas
  $00000000004C3191 line 306 of ../libraries/fpgui/src/gui/fpg_form.pas
  $0000000000494650 line 2504 of ../libraries/fpgui/src/corelib/fpg_base.pas
  $00000000004079D9 line 1134 of eschecs.pas
  $00000000004079D9 line 1134 of eschecs.pas

line 350 of eschecs.pas-> InitForm;

So something created in the InitForm procedure was not freed. Maybe check if you freed a pointer to a object vs the object him self.

I agree that this last memory leak is well hidden, I did find it (but did not search a lot).

Good luck!

Don't you think that the project is ready for a release?

Maybe if there is no memory leak.

;-)

Fre;D

rchastain commented 6 years ago

Thank you Fred. Let me some minutes. :)

rchastain commented 6 years ago

I don't know why I cannot reproduce the trace call that you reported.

I added this. I don't know if it solves the problem.

destructor TMainForm.Destroy;
begin
  ...
  FChessboardWidget.Free; // <---
  inherited Destroy;
end;

I commit that and continue to check the code.

rchastain commented 6 years ago

I also added a "FTimer.Free". I see no other candidate. :)

fredvs commented 6 years ago

Hello Roland.

Sadly FChessboardWidget.Free and FTimer.Free did not solve. ;(

fredvs commented 6 years ago

I moved the INI file to the config/ directory.

Here it still needs ENG file in root diretory.

rchastain commented 6 years ago

Hello, Fred! OK, I will continue to look for the memory leak.

What you say about the ENG file is surprising. I have no ENG file in root directory. I will try to understand.

rchastain commented 6 years ago

Sorry, Fred, I am stupid. Yes, the ENG file is needed in the root directory. Let me one minute.

fredvs commented 6 years ago

Hello Roland.

Yep, je l'ai!

And the guilty was...

---> rcmdline.pas---> generate memory leak (impossible to fix).

Here result of -ghl with -dOPT_SOUND without rcmdline.pas (and code referent):

Heap dump by heaptrc unit
9054 memory blocks allocated : 5574031/5591872
9054 memory blocks freed     : 5574031/5591872
0 unfreed memory blocks : 0
True heap size : 622592
True free heap : 622592

;)

Now, IMHO, (and if I was the King) I would remove rcmdline.pas from Eschecs code.

And, like I said before, for GUI application, I would forget to annoy people with parameters-command line.

With new release of Eschecs, everything can be configured graphically (with options-menu and friends).

That said, in my religion, it is NOT allowed to release programs that generate memory-leaks.

Now, if you agree to remove rcmdline (or find a more respectfull), I will follow you.

Fre;D

fredvs commented 6 years ago

Re-hello Roland.

If you absolutely want to use command-line parameters, what gives rcmdline that ParamStr(x) cannot give ?

rchastain commented 6 years ago

Hello Fred! I read your latest messages just now. Glad that you found the problem. OK, I remove that unit.

rchastain commented 6 years ago

Done. Unfortunately there is still a problem. Eschecs compiled with -dOPT_DEBUG and without -dOPT_SOUND. When the application closes.

Heap dump by heaptrc unit
47005 memory blocks allocated : 10024878/10132528
47003 memory blocks freed     : 10024814/10132456
2 unfreed memory blocks : 64
True heap size : 720896 (112 used in System startup)
True free heap : 720560
Should be : 720584
Call trace for block $01A48330 size 12
  $004132E8
  $0041F41B
  $0041F667
  $00403475  TMAINFORM__INITFORM,  line 488 of eschecs.pas
  $004029A2  TMAINFORM__AFTERCREATE,  line 336 of eschecs.pas
  $00452608  TFPGBASEFORM__AFTERCONSTRUCTION,  line 438 of ./gui/fpg_form.pas
  $0045215A  TFPGBASEFORM__CREATE,  line 306 of ./gui/fpg_form.pas
  $0043C109  TFPGAPPLICATIONBASE__CREATEFORM,  line 2504 of ./corelib/fpg_base.pas
Call trace for block $01A67778 size 52
  $00403475  TMAINFORM__INITFORM,  line 488 of eschecs.pas
  $004029A2  TMAINFORM__AFTERCREATE,  line 336 of eschecs.pas
  $00452608  TFPGBASEFORM__AFTERCONSTRUCTION,  line 438 of ./gui/fpg_form.pas
  $0045215A  TFPGBASEFORM__CREATE,  line 306 of ./gui/fpg_form.pas
  $0043C109  TFPGAPPLICATIONBASE__CREATEFORM,  line 2504 of ./corelib/fpg_base.pas
  $004056B4  main,  line 1088 of eschecs.pas
  $0045215A  TFPGBASEFORM__CREATE,  line 306 of ./gui/fpg_form.pas
  $0043C109  TFPGAPPLICATIONBASE__CREATEFORM,  line 2504 of ./corelib/fpg_base.pas

Maybe it's a problem that I created yesterday, when I was trying things to solve the memory leak. I have no time this morning. I will investigate this afternoon.

rchastain commented 6 years ago

After deleting all binaries and recompiling all, I get this call trace:

Heap dump by heaptrc unit
43309 memory blocks allocated : 4772807/4870200
43306 memory blocks freed     : 4770351/4867744
3 unfreed memory blocks : 2456
True heap size : 983040
True free heap : 980240
Should be : 980392
Call trace for block $053D0218 size 96
  $0043BB28  TFPGIMAGEBASE__CREATEMASKFROMSAMPLE,  line 2333 of ./corelib/fpg_base.pas
  $0044201A  TFPGIMAGES__ADDMASKEDBMP,  line 2749 of ./corelib/fpg_main.pas
  $0040246B  TMAINFORM__AFTERCREATE,  line 238 of eschecs.pas
  $00452608  TFPGBASEFORM__AFTERCONSTRUCTION,  line 438 of ./gui/fpg_form.pas
  $0045215A  TFPGBASEFORM__CREATE,  line 306 of ./gui/fpg_form.pas
  $0043C109  TFPGAPPLICATIONBASE__CREATEFORM,  line 2504 of ./corelib/fpg_base.pas
  $004056B4  main,  line 1088 of eschecs.pas
  $F0F0F0F0
Call trace for block $0012DB20 size 2304
  $00468C2E  READIMAGE_BMP,  line 177 of ./corelib/fpg_imgfmt_bmp.pas
  $00468B6D  CREATEIMAGE_BMP,  line 54 of ./corelib/fpg_imgfmt_bmp.pas
  $00441FBB  TFPGIMAGES__ADDBMP,  line 2738 of ./corelib/fpg_main.pas
  $00442001  TFPGIMAGES__ADDMASKEDBMP,  line 2746 of ./corelib/fpg_main.pas
  $0040246B  TMAINFORM__AFTERCREATE,  line 238 of eschecs.pas
  $00452608  TFPGBASEFORM__AFTERCONSTRUCTION,  line 438 of ./gui/fpg_form.pas
  $0045215A  TFPGBASEFORM__CREATE,  line 306 of ./gui/fpg_form.pas
  $0043C109  TFPGAPPLICATIONBASE__CREATEFORM,  line 2504 of ./corelib/fpg_base.pas
Call trace for block $001046F0 size 56
  $00468B5C  CREATEIMAGE_BMP,  line 53 of ./corelib/fpg_imgfmt_bmp.pas
  $00441FBB  TFPGIMAGES__ADDBMP,  line 2738 of ./corelib/fpg_main.pas
  $00442001  TFPGIMAGES__ADDMASKEDBMP,  line 2746 of ./corelib/fpg_main.pas
  $0040246B  TMAINFORM__AFTERCREATE,  line 238 of eschecs.pas
  $00452608  TFPGBASEFORM__AFTERCONSTRUCTION,  line 438 of ./gui/fpg_form.pas
  $0045215A  TFPGBASEFORM__CREATE,  line 306 of ./gui/fpg_form.pas
  $0043C109  TFPGAPPLICATIONBASE__CREATEFORM,  line 2504 of ./corelib/fpg_base.pas
  $004056B4  main,  line 1088 of eschecs.pas
fredvs commented 6 years ago

Hello Roland.

OK, je reprends les commandes. Please dont do new commits, I will do a pull-request.

Fre;D

fredvs commented 6 years ago

Hello Roland. Here result of your last commits with -ghl on Windows:

Heap dump by heaptrc unit
7817 memory blocks allocated : 5268639/5285288
7817 memory blocks freed     : 5268639/5285288
0 unfreed memory blocks : 0
True heap size : 1212416 (96 used in System startup)
True free heap : 1212320

and here on Linux:

Heap dump by heaptrc unit
9053 memory blocks allocated : 5573987/5591824
9053 memory blocks freed     : 5573987/5591824
0 unfreed memory blocks : 0
True heap size : 622592
True free heap : 622592

Here the command line that I used to compile on Windows:

fpc.exe -o/home/fred/eschecs/source/eschecs.exe -Fu../libraries/lazutils -Fi../libraries/lazutils -Fu./* -Fi./* -Fu../libraries/uos -Fi../libraries/uos -Fu../libraries -Fi../libraries -Fu../libraries/bgrabitmap -Fi../libraries/bgrabitmap -Fu../libraries/fpgui -Fi../libraries/fpgui -Fu../libraries/fpgui/src/corelib/gdi -Fi../libraries/fpgui/src/corelib/gdi -Fu../libraries/fpgui/src -Fi../libraries/fpgui/src -Fu../libraries/fpgui/src/gui -Fi../libraries/fpgui/src/gui -Fu../libraries/fpgui/src/corelib -Fi../libraries/fpgui/src/corelib -l -Mobjfpc -Schi -FE. -FUunits -ghl -B -O1 -XX -Xs -CX -dBGRABITMAP_USE_FPGUI -dOPT_SOUND -dOPT_HIGHLIGHT -vewnhibq /home/fred/eschecs/source/eschecs.pas

It is sad that you do not want to use ideU, everything would be much easier (for you and me).

Fre;D

fredvs commented 6 years ago

Re-hello Roland.

After test of your last releases, here some advices:

When you have done all your new commits, please prevent me, I have some few things to change.

Fre;D

rchastain commented 6 years ago

Hello Fred! I have no commit to do. So I let you the hand. When you have finished, I will fix the "illegal" sound bug and add a menu item for square coloring. Why everything would be easier if I used MSEide or ideU? If you want that I use the same compilation options than you, I can do that with or without using ideU. Or do I miss something? Regards. Roland

rchastain commented 6 years ago

If I want to use your PRJ file (I already tried), I have to modify it. If I modify it, it will no longer work for you.

rchastain commented 6 years ago

Using your command line, I get an EXE of 11,3 Mo. With my command line, 5,72 Mo. I wonder why the difference is so big.

rchastain commented 6 years ago

I cannot see again the call trace that I reported this morning. I don't know why: I didn't change anything, nor in the code, neither in the compilation options.

fredvs commented 6 years ago

Hello Roland.

Hello Martin.

I am here on a Windows 10 machine, compiling Eschecs with ideU.

Huh, indeed, here I get this result:

2 unfreed memory blocks : 64 True heap size : 229376 True free heap : 229056 Should be : 229176 Call trace for block $01FD5DF0 size 12 $00413168 $0041F1DB $0041F427 $004035E1 TMAINFORMINITFORM, line 534 of C:/eschecs/source/eschecs.pas $004029BF TMAINFORMAFTERCREATE, line 336 of C:/eschecs/source/eschecs.pas $0044E4C5 TFPGBASEFORMAFTERCONSTRUCTION, line 438 of C:/eschecs/libraries/fpgui/src/gui/fpg_form.pas $0044E050 TFPGBASEFORM__CREATE, line 306 of C:/eschecs/libraries/fpgui/src/gui/fpg_form.pas $BAADF00D Call trace for block $01FF5538 size 52 $004035E1 TMAINFORMINITFORM, line 534 of C:/eschecs/source/eschecs.pas $004029BF TMAINFORMAFTERCREATE, line 336 of C:/eschecs/source/eschecs.pas $0044E4C5 TFPGBASEFORMAFTERCONSTRUCTION, line 438 of C:/eschecs/libraries/fpgui/src/gui/fpg_form.pas $0044E050 TFPGBASEFORMCREATE, line 306 of C:/eschecs/libraries/fpgui/src/gui/fpg_form.pas $0043B6F9 TFPGAPPLICATIONBASE__CREATEFORM, line 2504 of C:/eschecs/libraries/fpgui/src/corelib/fpg_base.pas $0040563F main, line 1088 of C:/eschecs/source/eschecs.pas $004029BF TMAINFORMAFTERCREATE, line 336 of C:/eschecs/source/eschecs.pas $BAADF00D

What I do not understand is why it point as procedure TMAINFORM__INITFORM, line 534.

Line 534 = "begin" in procedure TMainForm.WidgetMouseMove.

???

I apologize, now I am loosed, why same compilateur used with wine emulator on Linux gives different result than in Windows 10. Who say the truth, heap-tracer of wine or Windows 10?

Mama mia. ;(

No, you do not need ideU or MSEide, we need the Pascal compiler of Martin.

Fre;D

fredvs commented 6 years ago

Re-hello Roland.

I will do a break this afternoon, you have the hand, read you tonight.

Fre;D

fredvs commented 6 years ago

`With my command line, 5,72 Mo. I wonder why the difference is so big.

With -ghl parameter too?

fredvs commented 6 years ago

If I modify it, it will no longer work for you.

If you use ideU, I let you Make option M,B,1,2,3,4. For Linux I will use Make option 5,6,7,8.

You may use also MSEide (but then there is only option M,B,1,2,3,4)

fredvs commented 6 years ago

Hello Roland.

I get it!

The problem comes from here in TMainForm.Destroy : if FEngineConnected then With Linux the engine is still connected at destroy, with Windows 10 no.

Here the fix (tested in Windows 10, Linux and Linux+wine):

destructor TMainForm.Destroy;
begin
  FBGRAChessboard.Free;
  FGame.Free;
  if FEngineConnected then
  begin
    WriteProcessInput_(MsgQuit());
    FreeConnectedProcess;
    vListener.Terminate;
    vListener.WaitFor;
  //  vListener.Free;  // this must be 2 lines down 
  end;
  vListener.Free;     // here no more memory leak!
  FMoveHistory.Free;
  FPositionHistory.Free;
  FValidator.Free;
  FreePictures;
  FChessboardWidget.Free;
  FTimer.Free;
  inherited Destroy;
end;

;) x 10

Fre;D

rchastain commented 6 years ago

Hello Fred! Congratulations. 💯 And sorry for having written that code, and never having seen the problem of freeing only if engine is connected. :) OK for your idea about ideU. I will install it. I make and commit your correction. Regards. Roland

rchastain commented 6 years ago

`With my command line, 5,72 Mo. I wonder why the difference is so big.

With -ghl parameter too?

Yes.

-dOPT_ECO
-dOPT_SOUND
-dOPT_DEBUG
-WG
-Mobjfpc
-Sh
-Sa
-B

#IFDEF OPT_DEBUG
#-gl
-ghl
#WRITE Compiling Debug Version
#ENDIF

-Fu..\units\bgrabitmap\
-Fu..\units\fpgui\
-Fu..\units\rcmdline\
-Fu..\units\uos\

-Fu.\chess\
-Fu.\eco\
-Fu.\uci\
-Fu.\validator\

-FU..\units\eschecs\
-FE..\

#-vm5024
#-vwhilq 
fredvs commented 6 years ago

Hello Roland.

With -ghl parameter too? Yes.

Maybe the verbosity?: -vewnhibq

fredvs commented 6 years ago

Re-hello Roland.

Note that the -ghl parameter is needed only for debugging, not for the release.

rchastain commented 6 years ago

Re-hello Fred!

Yes, maybe the verbosity.

Yes, I know for the -ghl parameter. Thank you.

I have just made a commit with a menu item for enabling/disabling square coloring.

The mysterious bug is back:

Call trace for block $05430168 size 96
  $0043C1C8  TFPGIMAGEBASE__CREATEMASKFROMSAMPLE,  line 2333 of ./corelib/fpg_base.pas
  $004426BA  TFPGIMAGES__ADDMASKEDBMP,  line 2749 of ./corelib/fpg_main.pas
  $0040247B  TMAINFORM__AFTERCREATE,  line 238 of eschecs.pas
  $004532E8  TFPGBASEFORM__AFTERCONSTRUCTION,  line 438 of ./gui/fpg_form.pas
  $00452E3A  TFPGBASEFORM__CREATE,  line 306 of ./gui/fpg_form.pas
  $0043C7A9  TFPGAPPLICATIONBASE__CREATEFORM,  line 2504 of ./corelib/fpg_base.pas
  $00405C19  main,  line 1094 of eschecs.pas
  $F0F0F0F0
rchastain commented 6 years ago

What does this code do?

fpgImages.AddMaskedBMP('vfd.eschecs', @vfd_eschecs, sizeof(vfd_eschecs), 0, 0);

Wouldn't it need a free?

fredvs commented 6 years ago

This code is to add icon image from resource for using icon-fpgui form.

fredvs commented 6 years ago

The mysterious bug is back:

Aaargh.

When you have done your commits, prevent me, I will investigate.

rchastain commented 6 years ago

Ok Fred. I have done all my commits. You have the hand.

fredvs commented 6 years ago

OK (but asap).

Fre;D