Spelt / ZXing.Delphi

ZXing Barcode Scanning object Pascal Library for Delphi VCL and Delphi Firemonkey
Apache License 2.0
471 stars 206 forks source link

Problems with iOS64 #49

Closed greyns closed 7 years ago

greyns commented 7 years ago

Hi,

When scanning QR Code, it works very fine with Firemonkey Win32, Win64, Android, iOS32 but I have a lot of problems with iOS64. No error is returned, only ReadResult = nil. Sometimes, it works, but only a few times. Once I had a floatingpoint error but I can't reproduce it.

Thanks for help. bv01

Spelt commented 7 years ago

Hi,

I can only help if you can reproduce the problem. Bug reports must have enough detail to understand and reproduce the problem.

Thanks,

On 18 Dec 2016, at 10:44, GREGOIRE REYNS notifications@github.com wrote:

Hi,

When scanning QR Code, it works very fine with Firemonkey Win32, Win64, Android, iOS32 but I have a lot of problems with iOS64. No error is returned, only ReadResult = nil. Sometimes, it works, but only a few times. Once I had a floatingpoint error but I can't reproduce it.

Thanks for help. https://cloud.githubusercontent.com/assets/17858461/21292739/db57b18c-c50e-11e6-8b25-2ebe2b561a94.jpg — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Spelt/ZXing.Delphi/issues/49, or mute the thread https://github.com/notifications/unsubscribe-auth/AMEt1YMl3qkhEfNLKAnmUsG-VylmKyZgks5rJQBlgaJpZM4LQFtI.

greyns commented 7 years ago

Thanks for reply. If you take your BigQR.png QRCode (or the QR Code I joined in my first message) and try to use it, the result will be nil with no exception under iOS64. All other platforms works fine (included iOS32 on an 64 bit iPad)

procedure TfrmParam.ScanImage(scanBitmap:TBitmap); var ReadResult: TReadResult; FScanManager: TScanManager; Hints: TDictionary<TDecodeHintType, TObject>; begin if scanBitmap = nil then exit;

Hints := nil; FScanManager := TScanManager.Create(TBarcodeFormat.QR_Code, Hints); ReadResult := nil;

try ReadResult := FScanManager.Scan(scanBitmap); except on E: Exception do begin FreeAndNil(ReadResult); FreeAndNil(FScanManager);

  ShowMessage(E.Message);
  Exit;
end;

end;

if (ReadResult <> nil) then begin ShowMessage(ReadResult.Text); end; end; FreeAndNil(ReadResult); FreeAndNil(FScanManager); end;

Spelt commented 7 years ago

It does sound like a compiler bug. Which Delphi version and which IOS version do you use ?

On 18 Dec 2016, at 16:03, GREGOIRE REYNS notifications@github.com wrote:

Thanks for reply. If you take your BigQR.png QRCode (or the QR Code I joined in my first message) and try to use it, the result will be nil with no exception under iOS64. All other platforms works fine (included iOS32 on an 64 bit iPad)

procedure TfrmParam.ScanImage(scanBitmap:TBitmap); var ReadResult: TReadResult; FScanManager: TScanManager; Hints: TDictionary<TDecodeHintType, TObject>; begin if scanBitmap = nil then exit;

Hints := nil; FScanManager := TScanManager.Create(TBarcodeFormat.QR_Code, Hints); ReadResult := nil;

try ReadResult := FScanManager.Scan(scanBitmap); except on E: Exception do begin FreeAndNil(ReadResult); FreeAndNil(FScanManager);

ShowMessage(E.Message); Exit; end; end;

if (ReadResult <> nil) then begin ShowMessage(ReadResult.Text); end; end; FreeAndNil(ReadResult); FreeAndNil(FScanManager); end;

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Spelt/ZXing.Delphi/issues/49#issuecomment-267826070, or mute the thread https://github.com/notifications/unsubscribe-auth/AMEt1eHgZkO1_mYVtok_AiA47PFWgOwhks5rJUswgaJpZM4LQFtI.

greyns commented 7 years ago

I'm using Delphi Berlin 10.1.2 and iOS 10.2. Win64 works fine (i thought it was a 64 bit issue) but the problem is only when compiling for iOS64. I can trace what you want, but I don't know where to have a look.

TRGBLuminanceSource ? THybridBinarizer ? TBinaryBitmap ? TMultiFormatReader ? Don't know at which level is the problem.

Spelt commented 7 years ago

Yes thats going to be hard to find. It does crash too sometimes you say? If so you can probably get it to crash with the debugger attached and that will get us further.

Just in case, I checked the Delphi Quality Central portal but there are no bug reported about this.

On 18 Dec 2016, at 16:14, GREGOIRE REYNS notifications@github.com wrote:

I'm using Delphi Berlin 10.1.2 and iOS 10.2. Win64 works fine (i thought it was a 64 bit issue) but the problem is only when compiling for iOS64. I can trace what you want, but I don't know where to have a look.

TRGBLuminanceSource ? THybridBinarizer ? TBinaryBitmap ? TMultiFormatReader ? Don't know at which level is the problem.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Spelt/ZXing.Delphi/issues/49#issuecomment-267826792, or mute the thread https://github.com/notifications/unsubscribe-auth/AMEt1YbLwkwdVOhoEA0qp6lKZyrBOIO7ks5rJU3wgaJpZM4LQFtI.

Spelt commented 7 years ago

Also which version of the zxing do you use? Latest pull in the v3 branch?

On 18 Dec 2016, at 16:38, Edward Spelt edwardspelt@gmail.com wrote:

Yes thats going to be hard to find. It does crash too sometimes you say? If so you can probably get it to crash with the debugger attached and that will get us further.

Just in case, I checked the Delphi Quality Central portal but there are no bug reported about this.

On 18 Dec 2016, at 16:14, GREGOIRE REYNS <notifications@github.com mailto:notifications@github.com> wrote:

I'm using Delphi Berlin 10.1.2 and iOS 10.2. Win64 works fine (i thought it was a 64 bit issue) but the problem is only when compiling for iOS64. I can trace what you want, but I don't know where to have a look.

TRGBLuminanceSource ? THybridBinarizer ? TBinaryBitmap ? TMultiFormatReader ? Don't know at which level is the problem.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Spelt/ZXing.Delphi/issues/49#issuecomment-267826792, or mute the thread https://github.com/notifications/unsubscribe-auth/AMEt1YbLwkwdVOhoEA0qp6lKZyrBOIO7ks5rJU3wgaJpZM4LQFtI.

greyns commented 7 years ago

No crash but one time I had an exception with a Floating point error, but it was at the beginning and I didn't knew the problem was with iOS64, so I didn't wrote the error. Since, with dozens of tests, no exception. I am going to trace but it will not be easy....

greyns commented 7 years ago

Yes last pull in the v3 branch, downloaded yesterday

Spelt commented 7 years ago

Hi Gregoire (French?)

I did some testing with the aTestApp project on my iPhone 6 and scanning just works here.

using

but did experience a crash but also got a lot of positive reads.

I will update IOS to 10.2 and also update XCode and do a device sync.

On 18 Dec 2016, at 16:46, GREGOIRE REYNS notifications@github.com wrote:

Yes last pull in the v3 branch, downloaded yesterday

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Spelt/ZXing.Delphi/issues/49#issuecomment-267828488, or mute the thread https://github.com/notifications/unsubscribe-auth/AMEt1a7e8Jzu2TYIoLS-x2uzVDTSnNdTks5rJVVpgaJpZM4LQFtI.

greyns commented 7 years ago

Yes, French. I don't know if it can help. Going through functions stepp by step, the last one with result=nil is the follwing one because resultOffset <> version.TotalCodewords

function TBitMatrixParser.readCodewords: TArray; var formatInfo: TFormatInformation; dimension, resultOffset, currentByte, bitsRead, j, i, count, col: Integer; functionPattern: TBitMatrix; readingUp: boolean; Version: TVersion; DataMask: TDataMask; begin Result := nil;

formatInfo := readFormatInformation; if (formatInfo = nil) then exit;

Version := readVersion; if (Version = nil) then exit;

// Get the data mask for the format used in this QR Code. This will exclude // some bits from reading as we wind through the bit matrix. DataMask := TDataMask.forReference(formatInfo.DataMask); dimension := bitMatrix.Height; DataMask.unmaskBitMatrix(BitMatrix, dimension);

functionPattern := Version.buildFunctionPattern;

try readingUp := true; Result := TArray.Create(); SetLength(Result, version.TotalCodewords); resultOffset := 0; currentByte := 0; bitsRead := 0; j := (dimension - 1); // Read columns in pairs, from right to left while ((j > 0)) do begin if (j = 6) then // Skip whole column with vertical alignment pattern; // saves time and makes the other code proceed more cleanly Dec(j); // Read alternatingly from bottom to top then top to bottom for count := 0 to Pred(dimension) do begin if (readingUp) then i := ((dimension - 1) - count) else i := count; for col := 0 to Pred(2) do begin // Ignore bits covered by the function pattern if (not functionPattern[(j - col), i]) then begin // Read a bit Inc(bitsRead); currentByte := (currentByte shl 1); if (bitMatrix[(j - col), i]) then currentByte := (currentByte or 1); // If we've made a whole byte, save it off if (bitsRead = 8) then begin // if resultoffset > high(Result) then // raise EProgrammerNotFound.CreateFmt('resultoffset %d> high(Result) %d',[resultOffset,high(Result)]) // else if resultoffset < 0 then // raise EProgrammerNotFound.CreateFmt('resultoffset %d<0!',[resultOffset]);

          if (resultoffset>=0) and  (resultoffset <= high(Result)) then // minchiata aggiunta da carlo
              Result[resultOffset] := Byte(currentByte);

          Inc(resultOffset);
          bitsRead := 0;
          currentByte := 0;
        end
      end;
    end;
  end;
  readingUp := not readingUp; // readingUp = !readingUp; // switch directions
  Dec(j, 2);
end;

if (resultOffset <> version.TotalCodewords)
then
   Result := nil;

finally FreeAndNil(functionPattern); end; end;

Spelt commented 7 years ago

I’m doing some investigation too.

I did see a crash and noticed a fmx.tbitmap crash. I’ll keep you posted.

On 18 Dec 2016, at 18:47, GREGOIRE REYNS notifications@github.com wrote:

Yes, French. I don't know if it can help. Going through functions stepp by step, the last one with result=nil is the follwing one because resultOffset <> version.TotalCodewords

function TBitMatrixParser.readCodewords: TArray; var formatInfo: TFormatInformation; dimension, resultOffset, currentByte, bitsRead, j, i, count, col: Integer; functionPattern: TBitMatrix; readingUp: boolean; Version: TVersion; DataMask: TDataMask; begin Result := nil;

formatInfo := readFormatInformation; if (formatInfo = nil) then exit;

Version := readVersion; if (Version = nil) then exit;

// Get the data mask for the format used in this QR Code. This will exclude // some bits from reading as we wind through the bit matrix. DataMask := TDataMask.forReference(formatInfo.DataMask); dimension := bitMatrix.Height; DataMask.unmaskBitMatrix(BitMatrix, dimension);

functionPattern := Version.buildFunctionPattern;

try readingUp := true; Result := TArray.Create(); SetLength(Result, version.TotalCodewords); resultOffset := 0; currentByte := 0; bitsRead := 0; j := (dimension - 1); // Read columns in pairs, from right to left while ((j > 0)) do begin if (j = 6) then // Skip whole column with vertical alignment pattern; // saves time and makes the other code proceed more cleanly Dec(j); // Read alternatingly from bottom to top then top to bottom for count := 0 to Pred(dimension) do begin if (readingUp) then i := ((dimension - 1) - count) else i := count; for col := 0 to Pred(2) do begin // Ignore bits covered by the function pattern if (not functionPattern[(j - col), i]) then begin // Read a bit Inc(bitsRead); currentByte := (currentByte shl 1); if (bitMatrix[(j - col), i]) then currentByte := (currentByte or 1); // If we've made a whole byte, save it off if (bitsRead = 8) then begin // if resultoffset > high(Result) then // raise EProgrammerNotFound.CreateFmt('resultoffset %d> high(Result) %d',[resultOffset,high(Result)]) // else if resultoffset < 0 then // raise EProgrammerNotFound.CreateFmt('resultoffset %d<0!',[resultOffset]);

      if (resultoffset>=0) and  (resultoffset <= high(Result)) then // minchiata aggiunta da carlo
          Result[resultOffset] := Byte(currentByte);

      Inc(resultOffset);
      bitsRead := 0;
      currentByte := 0;
    end
  end;
end;

end; readingUp := not readingUp; // readingUp = !readingUp; // switch directions Dec(j, 2); end;

if (resultOffset <> version.TotalCodewords) then Result := nil; finally FreeAndNil(functionPattern); end; end;

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Spelt/ZXing.Delphi/issues/49#issuecomment-267835280, or mute the thread https://github.com/notifications/unsubscribe-auth/AMEt1bfCrE0KsRkmz3vGleVMMgWHBOBJks5rJXGmgaJpZM4LQFtI.

Spelt commented 7 years ago

Good news !

I think I got it. I noticed the following:

If I remove in the aTestApp the TTask code it all works. It does scan everything and does not crash.

Can you confirm this to me?

After some further reading I noticed this bug report: https://quality.embarcadero.com/browse/RSP-16377?jql=project%20%3D%20RSP%20AND%20issuetype%20%3D%20Bug%20AND%20affectedVersion%20%3D%20%2210.1%20Berlin%20Update%202%22%20AND%20status%20%3D%20Open%20ORDER%20BY%20priority%20DESC https://quality.embarcadero.com/browse/RSP-16377?jql=project%20=%20RSP%20AND%20issuetype%20=%20Bug%20AND%20affectedVersion%20=%20%2210.1%20Berlin%20Update%202%22%20AND%20status%20=%20Open%20ORDER%20BY%20priority%20DESC

It suspect that it has something to do with this.

On 18 Dec 2016, at 12:00, Edward Spelt edwardspelt@gmail.com wrote:

Hi,

I can only help if you can reproduce the problem. Bug reports must have enough detail to understand and reproduce the problem.

Thanks,

On 18 Dec 2016, at 10:44, GREGOIRE REYNS <notifications@github.com mailto:notifications@github.com> wrote:

Hi,

When scanning QR Code, it works very fine with Firemonkey Win32, Win64, Android, iOS32 but I have a lot of problems with iOS64. No error is returned, only ReadResult = nil. Sometimes, it works, but only a few times. Once I had a floatingpoint error but I can't reproduce it.

Thanks for help. https://cloud.githubusercontent.com/assets/17858461/21292739/db57b18c-c50e-11e6-8b25-2ebe2b561a94.jpg — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Spelt/ZXing.Delphi/issues/49, or mute the thread https://github.com/notifications/unsubscribe-auth/AMEt1YMl3qkhEfNLKAnmUsG-VylmKyZgks5rJQBlgaJpZM4LQFtI.

greyns commented 7 years ago

Hi,

I have tried but it still craches compiled iOS64 but we have a few detection on QR Code while it is not crashing anymore compiled iOS32 with very good detection. So there is a problem with iOS64 compiling. I have modify your app, likethis you can load a picture on iOS or takeonly one picture from camera.

If you load your BigQR on your iPhone, you can load it into your app. Compiled for iOS32, it works perfectly. Compiled for iOS64, BigQR is not analyzed correctly and result = nil

I have an iPad Mini 4 -iOS10.2 - XCode 8.2 - Delphi 10.1.2 - ZXing V3

aTestApp.zip

Spelt commented 7 years ago

Hi

I tested it again and it still works here :-) However, I did see a difference with your code. You should also comment out the back to ui thread Synchronizations.

I attached my latest test project. I cleaned it up so its much real worl and more clear. I commented out the exception causing bits.

Note 1: while scanning I did saw some floating point exception which got eaten. This is by design (also in the .net version). You only see this in debug modus.

Note 2: In IOS32 I get exceptions and crashes in the original sample too. Something is smelly in the TThreading class.

Hope it helps! Let me know.

2016-12-19 8:38 GMT+01:00 GREGOIRE REYNS notifications@github.com:

Hi,

I have tried but it still craches compiled iOS64 but we have a few detection on QR Code while it is not crashing anymore compiled iOS32 with very good detection. So there is a problem with iOS64 compiling. I have modify your app, likethis you can load a picture on iOS or takeonly one picture from camera.

If you load your BigQR on your iPhone, you can load it into your app. Compiled for iOS32, it works perfectly. Compiled for iOS64, BigQR is not analyzed correctly and result = nil

I have an iPad Mini 4 -iOS10.2 - XCode 8.2 - Delphi 10.1.2 - ZXing V3

aTestApp.zip https://github.com/Spelt/ZXing.Delphi/files/660368/aTestApp.zip

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Spelt/ZXing.Delphi/issues/49#issuecomment-267900339, or mute the thread https://github.com/notifications/unsubscribe-auth/AMEt1QID3GG7CvlnpE8MYaofL4g-rdUWks5rJjSBgaJpZM4LQFtI .

greyns commented 7 years ago

Hi, I think you forgot the attachment. I really have two differents behaviors between iOS32 and iOS64, but we can't debug in iOS32 for the moment. So I can't compare. I have reduce the resolution of the pictures in take with my app and the scan is getting better in iOS64 (1/2), mostly in good light conditions. In iOS32, Android and Win32/Win64, the scan is succesfull nearly everytime.

Thanks for the job. I will continue to investigate and teel you if I find something. Send me your test app if you want me to test it.

Regards

Greg

Spelt commented 7 years ago

atestapp zip

Github does not like my zips. I renamed it and posted it again. Right Click and save as

greyns commented 7 years ago

it works much more better. No More crash (iOS32/iOS64) and the detection with my QR Code is better too. Thanks for all.

Spelt commented 7 years ago

Great, glad to help!

Op 20 dec. 2016 om 14:19 heeft GREGOIRE REYNS notifications@github.com het volgende geschreven:

it works much more better. No More crash (iOS32/iOS64) and the detection with my QR Code is better too. Thanks for all.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

Spelt commented 7 years ago

Btw

How do you gonna replace the ttask code? With a ttimer?

Op 20 dec. 2016 om 14:19 heeft GREGOIRE REYNS notifications@github.com het volgende geschreven:

it works much more better. No More crash (iOS32/iOS64) and the detection with my QR Code is better too. Thanks for all.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

greyns commented 7 years ago

I am not using realtime scanning. I take a picture from the camera or from the library and I analyse it in my app. But your test app gave me some ideas... Maybe later, when I will have time.

maurobotta commented 7 years ago

Any news on Tokyo ?

Spelt commented 7 years ago

Second line :-) https://github.com/Spelt/ZXing.Delphi

2017-05-02 12:16 GMT+02:00 Mauro Botta notifications@github.com:

Any news on Tokyo ?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/Spelt/ZXing.Delphi/issues/49#issuecomment-298593478, or mute the thread https://github.com/notifications/unsubscribe-auth/AMEt1bLXpVcZtnvdPhjXOSWrjW1Wh7okks5r1wKUgaJpZM4LQFtI .