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.







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

Thank you all.




Share this post

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

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

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

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

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


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

Edited by f.m

Share this post

Link to post

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.



procedure TForm1.UpdatePreview;

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

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

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




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


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



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:


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.













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