View Issue Details

IDProjectCategoryView StatusLast Update
0029720LazarusLCLpublic2016-02-26 12:19
ReporterdonovalyAssigned ToBart Broersma 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionno change required 
PlatformWinOSWinOS VersionWin 7
Product Version1.6Product Build 
Target VersionFixed in Version 
Summary0029720: regression: Drag/Drop files crashes programs compiled with Lazarus 1.6
Description- Compile a program of your choice where dragging in files is enabled
 (http://lazplanet.blogspot.de/2013/05/drag-drop-files-lazarus-form.html)
 with Lazarus 1.6
- drag in e.g. a textfile

result: your program will crash!

- compile the same program with Lazarus 1.4.x and everything works fine.

I can upload a small test program when you like.

This is a very sever bug hindering me to release anything compiled with Lazarus 1.6.
Maybe this is a bug in FPC, I don't know.
TagsNo tags attached.
Fixed in Revision
LazTarget-
WidgetsetWin32/Win64
Attached Files

Activities

Bart Broersma

2016-02-24 23:08

developer   ~0090257

Please attach a compilable sample project (sources only) demonstrating the problem.

donovaly

2016-02-24 23:26

reporter  

Drag-Crash.zip (159,355 bytes)

donovaly

2016-02-24 23:30

reporter   ~0090262

- compile the attached project
- run the executable
- drag in the test.txt file from the attached project

-> Crash when you run the executable from within Lazarus. If you start the executable without Lazarus one only gets the attached error message and then nothing happens

donovaly

2016-02-24 23:31

reporter  

Lazarus-drag-error.jpg (170,307 bytes)
Lazarus-drag-error.jpg (170,307 bytes)

donovaly

2016-02-24 23:32

reporter  

Lazarus-drag-crash.jpg (244,397 bytes)
Lazarus-drag-crash.jpg (244,397 bytes)

Bart Broersma

2016-02-25 11:19

developer  

dd.zip (65,438 bytes)

Bart Broersma

2016-02-25 11:21

developer   ~0090288

Uploaded a minimal testcase.

procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of String);
var
  i: Integer;
begin
  for i := Low(FileNames) to High(FileNames) do
    writeln(i,' ',FileNames[i]);
end;

It runs without any errors.

Sample output:
0 C:\Users\Bart\LazarusProjecten\bugs\DragFiles\drag.exe
1 C:\Users\Bart\LazarusProjecten\bugs\DragFiles\drag.ico
2 C:\Users\Bart\LazarusProjecten\bugs\DragFiles\drag.lpi
3 C:\Users\Bart\LazarusProjecten\bugs\DragFiles\drag.lpi.bak
4 C:\Users\Bart\LazarusProjecten\bugs\DragFiles\drag.lpr
5 C:\Users\Bart\LazarusProjecten\bugs\DragFiles\drag.lps
6 C:\Users\Bart\LazarusProjecten\bugs\DragFiles\drag.lps.bak
7 C:\Users\Bart\LazarusProjecten\bugs\DragFiles\drag.res
8 C:\Users\Bart\LazarusProjecten\bugs\DragFiles\main.lfm
9 C:\Users\Bart\LazarusProjecten\bugs\DragFiles\main.lfm.bak
10 C:\Users\Bart\LazarusProjecten\bugs\DragFiles\main.pp
11 C:\Users\Bart\LazarusProjecten\bugs\DragFiles\main.pp.bak
Heap dump by heaptrc unit
1923 memory blocks allocated : 1844448/1850752
1923 memory blocks freed : 1844448/1850752
0 unfreed memory blocks : 0
True heap size : 688128 (112 used in System startup)
True free heap : 688016

The error must be somewhere in your program I guess.

Bart Broersma

2016-02-25 11:31

developer   ~0090289

I cannot open your project since it depends on a component I have not isntalled.

procedure TMainForm.FormDropFiles(const FileNames: array of String);
begin
 DropfileName:= FileNames[0];
 OpenClick;
 DropfileName:= '';
end;

This will crash if FileNames is empty.
You should always use a construct like in my example above, checking Low(FileNames) and High(FileNames), or use something like:

  if (Length(FileNames) > 0) then DropfileName:= FileNames[0];

Bart Broersma

2016-02-25 11:31

developer   ~0090290

User error.
Please close.

donovaly

2016-02-25 17:23

reporter   ~0090308

> The error must be somewhere in your program I guess.

But why does it not crash when I compile the same program with Lazarus 1.4.4?

FileNames is not empty.

Besides this, why do you close the bug before I had a chance to reply? You say that you cannot compile my project so how can you be sure it is a fault of mine?

You said you uploaded a minimal testcase but I cannot see it here.

Bart Broersma

2016-02-25 17:58

developer   ~0090316

> Besides this, why do you close the bug before I had a chance to reply?
Because my minimal test case proved that DropFiles works as expected.

There may very well be other problems in your program, that eventually may lead up to the described crash, but I cannot (and will not) investigate that.
You may want to build your app with all checks on.

> FileNames is not empty.
How did you test?

> You said you uploaded a minimal testcase but I cannot see it here.
2016-02-25 11:19 Bart Broersma File Added: dd.zip
It's just below your screenshots.

Please build and run my test app.
Run it from outside the IDE.
Open explorer, select and drop some files on it.

Report back if it crashes.
Also please state wether you are using 64-bit fpc or 32-bit.

donovaly

2016-02-25 21:14

reporter   ~0090317

Thanks Bart. Your example project works fine but my program still crashes. I have this code:

procedure TMainForm.FormDropFiles(const FileNames: array of String);
begin
 if (Length(FileNames) > 0) then
  DropfileName:= FileNames[0];
 DropfileName:= '';
end;

When I set a breakpoint I see that the if is true, therefore
DropfileName:= FileNames[0];
is executed and when this is executed I get the crash. Attached is the screenshot of the appearing assembler window.

I have no clue what is going on since everything is fine with Lazarus 1.4.4 on the same project.

donovaly

2016-02-25 21:14

reporter  

Lazarus-drag-error-Assembler.jpg (521,018 bytes)

donovaly

2016-02-25 21:21

reporter   ~0090318

Before it crashes the content of FileNames is:

Len=1: (0x60e508 0000248#4)

DropfileName is a string type and I explicitly emptied it.

> please state wether you are using 64-bit fpc or 32-bit.

I use this Lazarus version:
https://sourceforge.net/projects/lazarus/files/Lazarus%20Windows%2032%20bits/Lazarus%201.6/lazarus-1.6.0-fpc-3.0.0-win32.exe/download

Bart Broersma

2016-02-25 23:00

developer   ~0090321

Your declaration:
procedure TMainForm.FormDropFiles(const FileNames: array of String);

must be:
procedure TMainForm.FormDropFiles(Sender: TObject; const FileNames: array of String);
Note the first parameter: Sender!

You must have edited this yourself.
The signature of OnDropFiles has not changed between 1.4 and 1.6

When I changed it into the correct definition, your program did not crash anymore.

donovaly

2016-02-26 00:51

reporter   ~0090325

> Note the first parameter: Sender!

many thanks! This fixes this it.

> You must have edited this yourself.

Yes, because now I get again this warning when compiling:

Roughness.pas(59,29) Verbose: Parameter "Sender" not used

I had already a discussion about this with your colleague. The default setting is to show all messages. OK, I can disable Verbose, but why do I get a message "Parameter "Sender" not used" if Sender _is_ used as in my case with drag and drop? In my opinion this is a bug and should be fixed. if you like I can report this as separate bug.

Once again many thanks for your help and best regards

Bart Broersma

2016-02-26 12:19

developer   ~0090336

> why do I get a message "Parameter "Sender" not used" if Sender _is_ used
It's not used _in your code_, but it's on the stack nevertheless.
Your faulty code then acceessed the wrong memory.

> because now I get again this warning when compiling:
1. It's a warning, not an error.
2. The IDE offers a method to suppress the warning ("quick fix": right-click on the message in questio to see the option. It'll the insert a {%H-} in front of the Sender parameter in the parameterlist).
3. You can reduce verbosity if so desired.
4. Event methods must have a fixed signature, so just removing a paramter from it is a big no-no.

Please close this issue.
Discussions about this should go to the forum or mailinglist.

Issue History

Date Modified Username Field Change
2016-02-24 23:01 donovaly New Issue
2016-02-24 23:08 Bart Broersma LazTarget => -
2016-02-24 23:08 Bart Broersma Note Added: 0090257
2016-02-24 23:08 Bart Broersma Status new => feedback
2016-02-24 23:26 donovaly File Added: Drag-Crash.zip
2016-02-24 23:30 donovaly Note Added: 0090262
2016-02-24 23:30 donovaly Status feedback => new
2016-02-24 23:31 donovaly File Added: Lazarus-drag-error.jpg
2016-02-24 23:32 donovaly File Added: Lazarus-drag-crash.jpg
2016-02-25 11:19 Bart Broersma File Added: dd.zip
2016-02-25 11:21 Bart Broersma Note Added: 0090288
2016-02-25 11:31 Bart Broersma Note Added: 0090289
2016-02-25 11:31 Bart Broersma Note Added: 0090290
2016-02-25 11:31 Bart Broersma Status new => resolved
2016-02-25 11:31 Bart Broersma Resolution open => no change required
2016-02-25 11:31 Bart Broersma Assigned To => Bart Broersma
2016-02-25 17:23 donovaly Note Added: 0090308
2016-02-25 17:50 Bart Broersma Status resolved => assigned
2016-02-25 17:50 Bart Broersma Resolution no change required => reopened
2016-02-25 17:58 Bart Broersma Note Added: 0090316
2016-02-25 17:58 Bart Broersma Status assigned => feedback
2016-02-25 21:14 donovaly Note Added: 0090317
2016-02-25 21:14 donovaly Status feedback => assigned
2016-02-25 21:14 donovaly File Added: Lazarus-drag-error-Assembler.jpg
2016-02-25 21:21 donovaly Note Added: 0090318
2016-02-25 23:00 Bart Broersma Note Added: 0090321
2016-02-25 23:00 Bart Broersma Status assigned => resolved
2016-02-25 23:00 Bart Broersma Resolution reopened => no change required
2016-02-26 00:51 donovaly Note Added: 0090325
2016-02-26 12:19 Bart Broersma Note Added: 0090336