Jump to content
Wesley Bobato

[bug] Camera + Effects

Recommended Posts

Hello everyone, I created a simple project that uses Camera and Effects with FMX


unfortunately this project is generating some unknown runtime errors
I can't find the root of the problem
I added in the DPR file all FMX options

 

1. Slow processing when GlobalUseGPUCanvas = false
2. When I use the effects after a while it crashes, it does not allow to stop the camera and etc.

 

To generate the different errors you can uncomment the lines of the DPR file.
1. Activate the camera.
2. Click on effects.
3. Use the effects options.
4. Disable the camera.
5. Repeat steps 1 through 4.

 

DPR file lines to uncomment.
// GlobalUseHWEffects := False;
// GlobalDisableFocusEffect := True;
// GlobalUseDX := False;
// GlobalUseDXInDX9Mode := True;
// GlobalUseDXSoftware := True;
// GlobalUseDirect2D := False;
// GlobalUseGDIPlusClearType := False;
// GlobalUseGPUCanvas := True;
// GlobalUseDX10 := False;
// GlobalUseDX10Software := False;

 

I added FastMM4 is commented in the DPR file
// FastMM4,

 

As you use the effects combining with DPR file options uncomment the different lines kinds of problems appear.

 

I noticed that the amount of camera FPS gets smaller at times as well.


I am using Windows 7 SP1 and Delphi 10.3.2, errors appear in Win 32/64 Debug and Release environment.

 

camera1.thumb.png.419b43908a080a7a855fb0bcff7b1ca1.png

camera2.thumb.png.14f7e55fd038841eeb533219b995e835.png

camera3.png.1f164d26126813a434c5437343fbeba8.png

camera4.png.46ac628d7cd86e9b1e4bf5cb47058832.png

 

Could someone help me locate these errors for me to create a ticket in the quality portal of embarcadero?

Thank you all.

 

[Download]

Camera.zip

Share this post


Link to post
procedure TForm1.SampleBufferReady(Sender: TObject; const ATime: TMediaTime);
begin
  if FUpdatePreviewExecuting then
    Exit;
  ..
end;

procedure TForm1.SetEffect(const AFilterName: string);
begin
  if FUpdatePreviewExecuting then
    Exit;
  ...
end;

procedure TForm1.UpdatePreview;
begin
  FUpdatePreviewExecuting := True;
  try
    FFilter.ValuesAsBitmap[ 'Input' ] := FRawBitmap;

    if not FTargetBitmap.IsEmpty then
      FFilter.ValuesAsBitmap[ 'Target' ] := FTargetBitmap;

    imgCam.Bitmap := FFilter.ValuesAsBitmap[ 'Output' ];
  finally
    FUpdatePreviewExecuting := False;
  end;
end;

 

SampleBufferReady() is probably synchronized via TThread.Synchronize(). Try to protect UpdatePreview() with a flag.

Edited by f.m

Share this post


Link to post

Hi,
I add some information.
I tested your project in the following configuration:
- 10.3.2, Windows 10;
- I have not removed the comment to any of the Global.. flags in DPR file;
- I didn't use FastMM4.

 

I performed two tests:
A) Without using TVideoCaptureDevice. I used a timer and some images: The program works. It is possible to change effects, and use effects options without errors.
This leads me to believe that the problem is TVideoCaptureDevice:
B) Using TVideoCaptureDevice. Generates exception, which is removed if I use the flag ("if FUpdatePreviewExecuting..") in the SampleBufferReady () method.


Test procedure:
1) [Play]
2) [Effect]
3) Click on effect
4) Changing effect parameters
5) Repeat from step 3.

Share this post


Link to post

@f.m thank you very much for your generous attention again :)

 

I tested your suggestion but unfortunately generated a very long delay
was crashing a lot.

 

Based on your suggestion I changed a few lines.

Quote

 

procedure TForm1.UpdatePreview;
begin

  TThread.CreateAnonymousThread( procedure()
   begin
    FFilter.ValuesAsBitmap[ 'Input' ] := FRawBitmap;

    if not FTargetBitmap.IsEmpty then
      FFilter.ValuesAsBitmap[ 'Target' ] := FTargetBitmap;

    TThread.Synchronize( TThread.Current, procedure()
     begin
       imgCam.Bitmap := FFilter.ValuesAsBitmap[ 'Output' ];
     end );
   end ).Start;

end;

 

 

This didn't work correctly either, but it is having a shorter delay.

 

When you have thrown exceptions on your computer you can capture which unit or line of code it is in.
is this occurring?

 

Here on my computer I can't capture the location of the problem even with Debug and FastMM4.

 

I believe there is a problem with TVideoCaptureDevice but it is very difficult to capture the location

 

Do you know any way to track where these exceptions occur in Delphi?

 

Kind regards.

Share this post


Link to post

Hi,

This exception occurs in the FMX.Canvas.D2D file on the line 1996 .

 

753674868_Exceptionmessage.thumb.jpg.96f80e9109aef99120165a42affb783a.jpg

Share this post


Link to post

A stack trace would be more helpful. It should appear after you click "Break". If not, click View > Debug Windows > Call Stack or just use Ctrl-Alt-S

Share this post


Link to post

Thank you.
Here is the stack trace:

Stack.thumb.jpg.ee3f170fc082c1c91645cc0a11297783.jpg

The exception occurs in the original version of the code. By protecting the UpdatePreview () method with a flag, this exception does not occur.

Share this post


Link to post

Hello it is very difficult to find the possible locations where the problem occurs, my intuition after examining all the points of the stack, is that the problem is related to "FMX.Media" some synchronization not working properly, I get several errors after a few minutes of testing.

 

Particularly the line reported by @fm did not occur here in my tests, I tested this project's compile on another computer and got different errors on Win10.

 

Any suggestions how I can report this to embarcadero?

 

Thank you all.

 

001.thumb.png.f6751d493e2de354a61f6ebae0113d71.png

002.thumb.png.03110c25b54bcea3bcc3f019bb2b1224.png

003.thumb.png.bd5a75ac735100774945a4ee1bdd29f9.png

004.thumb.png.c85eecdae970b4dddfd6e951950105f6.png

005.thumb.png.86fca90c5950a614c7d86b466c41ff98.png

006.thumb.png.dcb65919b31a5175665077225b5e3f74.png

007.thumb.png.6dd9fd29312c1805f4efe684a0e62033.png

008.thumb.png.b10944f1f371e6791201beb6879055de.png

009.thumb.png.fa3564af5c6da8550ee0d6e034fbb8c0.png

 

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×