Recent

Author Topic: MPlayer Access Violation  (Read 8778 times)

abtaylr

  • Full Member
  • ***
  • Posts: 107
MPlayer Access Violation
« on: April 09, 2016, 03:24:20 pm »
I am consistently getting an EAccessViolation:

[FORMS.PP] ExceptionOccurred
  Sender=EAccessViolation
  Exception=Access violation
  Stack trace:
  $00000000007B24F9 line 23 of ../../FreePascal/lazarus-1.6.0/lcl/include/controlcanvas.inc
  $000000000098468B line 537 of ../../FreePascal/lazarus-1.6.0/components/mplayer/mplayerctrl.pas
  $00000000005A6953 line 905 of ../../FreePascal/fpc-3.0.0/rtl/objpas/classes/reader.inc
  $00000000005A7568 line 1006 of ../../FreePascal/fpc-3.0.0/rtl/objpas/classes/reader.inc
  $00000000005971AD line 320 of ../../FreePascal/fpc-3.0.0/rtl/objpas/classes/compon.inc
  $00000000007DD94B line 3668 of ../../FreePascal/lazarus-1.6.0/lcl/include/control.inc
  $00000000005A6CBB line 957 of ../../FreePascal/fpc-3.0.0/rtl/objpas/classes/reader.inc
  $00000000005A7568 line 1006 of ../../FreePascal/fpc-3.0.0/rtl/objpas/classes/reader.inc
  $00000000005971AD line 320 of ../../FreePascal/fpc-3.0.0/rtl/objpas/classes/compon.inc
  $00000000007DD94B line 3668 of ../../FreePascal/lazarus-1.6.0/lcl/include/control.inc
  $00000000005A98DE line 1471 of ../../FreePascal/fpc-3.0.0/rtl/objpas/classes/reader.inc
  $00000000006E9866 line 3135 of ../../FreePascal/lazarus-1.6.0/lcl/lresources.pp
  $00000000006E965F line 3162 of ../../FreePascal/lazarus-1.6.0/lcl/lresources.pp
  $00000000006DEF5D line 800 of ../../FreePascal/lazarus-1.6.0/lcl/lresources.pp
  $000000000045C019 line 1978 of ../../FreePascal/lazarus-1.6.0/lcl/include/customform.inc
  $000000000045FCCB line 3070 of ../../FreePascal/lazarus-1.6.0/lcl/include/customform.inc
  $000000000046CDFE line 2163 of ../../FreePascal/lazarus-1.6.0/lcl/include/application.inc
TApplication.HandleException Access violation
  Stack trace:
  $00000000007B24F9 line 23 of ../../FreePascal/lazarus-1.6.0/lcl/include/controlcanvas.inc
  $000000000098468B line 537 of ../../FreePascal/lazarus-1.6.0/components/mplayer/mplayerctrl.pas
  $00000000005A6953 line 905 of ../../FreePascal/fpc-3.0.0/rtl/objpas/classes/reader.inc
  $00000000005A7568 line 1006 of ../../FreePascal/fpc-3.0.0/rtl/objpas/classes/reader.inc
  $00000000005971AD line 320 of ../../FreePascal/fpc-3.0.0/rtl/objpas/classes/compon.inc
  $00000000007DD94B line 3668 of ../../FreePascal/lazarus-1.6.0/lcl/include/control.inc
  $00000000005A6CBB line 957 of ../../FreePascal/fpc-3.0.0/rtl/objpas/classes/reader.inc
  $00000000005A7568 line 1006 of ../../FreePascal/fpc-3.0.0/rtl/objpas/classes/reader.inc
  $00000000005971AD line 320 of ../../FreePascal/fpc-3.0.0/rtl/objpas/classes/compon.inc
  $00000000007DD94B line 3668 of ../../FreePascal/lazarus-1.6.0/lcl/include/control.inc
  $00000000005A98DE line 1471 of ../../FreePascal/fpc-3.0.0/rtl/objpas/classes/reader.inc
  $00000000006E9866 line 3135 of ../../FreePascal/lazarus-1.6.0/lcl/lresources.pp
  $00000000006E965F line 3162 of ../../FreePascal/lazarus-1.6.0/lcl/lresources.pp
  $00000000006DEF5D line 800 of ../../FreePascal/lazarus-1.6.0/lcl/lresources.pp
  $000000000045C019 line 1978 of ../../FreePascal/lazarus-1.6.0/lcl/include/customform.inc
  $000000000045FCCB line 3070 of ../../FreePascal/lazarus-1.6.0/lcl/include/customform.inc
  $000000000046CDFE line 2163 of ../../FreePascal/lazarus-1.6.0/lcl/include/application.inc

The instance is created of the form ->resources are created->the font is checked->it reads its state->MPlayer then moves to TControlCanvas(FCanvas).Control := Self -> TCanvasControl.SetControl fails at line 23->
if FControl <> AControl then
  begin
    FreeHandle;
    FControl := AControl;
  end;

abtaylr

  • Full Member
  • ***
  • Posts: 107
Re: MPlayer Access Violation
« Reply #1 on: April 09, 2016, 03:26:02 pm »
I guess I should say I am on Kubuntu 15.10 64bit.

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1269
Re: MPlayer Access Violation
« Reply #2 on: April 09, 2016, 03:50:42 pm »
Odd.  I'm not overly familiar with that section of the code, though I did modify it slightly. 

Something you say is odd

Quote
MPlayer then moves to TControlCanvas(FCanvas).Control := Self -> TCanvasControl.SetControl fails at line 23

Line 23 is miles away.  It's line 537 in my copy.   I'm going to assume this isn't related though...

I just don't see why the code should be AV'ing though. 

Ummm, I'm a little out of depth - here's some suggestions:

Are you compiling using QT widgetset?  Try switching over to GTK2

If that's not it, then try changing TCustomMPlayerControl.Create(TheOwner: TComponent); to
Code: [Select]
constructor TCustomMPlayerControl.Create(TheOwner: TComponent);
begin
  inherited Create(TheOwner);
  ControlStyle:=ControlStyle-[csSetCaption];
  //FCanvas := TControlCanvas.Create;           // <- Change
  //TControlCanvas(FCanvas).Control := Self; // <- Change
  FCanvas := nil;                                                // <- New line

  SetInitialBounds(0, 0, 160, 90);

  FOutlist := TStringList.Create;

  FMPlayerPath := 'mplayer' + GetExeExt;

  FTimer := TTimer.Create(Self);
  FTimer.Enabled := False;
  FTimer.Interval := 250;
  FTimer.OnTimer := @TimerEvent;
end;

And then rebuild your IDE (maybe need clean all enabled)

If that works, then it's not a solution (you'll have flickering when a video isn't playing), but it'll give us some more information...



UPDATE: Wait :-)  Just had a thought.  Are you creating the component at runtime, or dropping it on a form in the IDE?  I've been assuming you were dropping this on a form at designtime.

if you're doing this at runtime, can you show us your creation code?  I'm wondering if you've got a nil Parent or Owner...

Many thanks

Mike
« Last Edit: April 09, 2016, 03:53:05 pm by Mike.Cornflake »
Lazarus Trunk/FPC latest fixes on Windows 11
  I'm getting old and stale.  Slowly getting used to git, I'll get there...

abtaylr

  • Full Member
  • ***
  • Posts: 107
Re: MPlayer Access Violation
« Reply #3 on: April 09, 2016, 06:40:22 pm »
I am using GTK2.  I've seen where some people experienced problems using QT.  This is my debug log:

TControlCanvas.SetControl

=thread-group-added,id="i1"
(gdb)
<-gdb-set confirm off>
^done
(gdb)
<-gdb-set new-console off>
^error,msg="No symbol table is loaded.  Use the \"file\" command."
(gdb)
<set width 50000>
&"set width 50000\n"
=cmd-param-changed,param="width",value="50000"
^done
. . . GDB advertising removed . . .
. . . GDB setup stuff . . .
. . . GDB library loading - startup . . .
. . . breakpoint I placed just ahead of mplayer @ TCustomMPlayerControl.Create line 537
(gdb)
<info line "/home/arlen/FreePascal/lazarus-1.6.0/components/mplayer/mplayerctrl.pas":537>
&"info line \"/home/arlen/FreePascal/lazarus-1.6.0/components/mplayer/mplayerctrl.pas\":537\n"
~"Line 537 of \"../../FreePascal/lazarus-1.6.0/components/mplayer/mplayerctrl.pas\" starts at address 0x984677 <Create+279> and ends at 0x98468b <Create+299>.\n"
^done
(gdb)
<-break-insert  "\"/home/arlen/FreePascal/lazarus-1.6.0/components/mplayer/mplayerctrl.pas\":537">
^done,bkpt={number="9",type="breakpoint",disp="keep",enabled="y",addr="0x0000000000984677",func="Create",file="../../FreePascal/lazarus-1.6.0/components/mplayer/mplayerctrl.pas",fullname="/home/arlen/FreePascal/lazarus-1.6.0/components/mplayer/mplayerctrl.pas",line="537",thread-groups=["i1"],times="0",original-location="/home/arlen/FreePascal/lazarus-1.6.0/components/mplayer/mplayerctrl.pas:537"}
(gdb)
<-break-enable 9>
^done
(gdb)
<-exec-continue>
^running
*running,thread-id="all"
(gdb)
=library-loaded,id="/usr/lib/x86_64-linux-gnu/gconv/UTF-16.so",target-name="/usr/lib/x86_64-linux-gnu/gconv/UTF-16.so",host-name="/usr/lib/x86_64-linux-gnu/gconv/UTF-16.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="/usr/lib/x86_64-linux-gnu/gtk-2.0/modules/libgtk-vector-screenshot.so",target-name="/usr/lib/x86_64-linux-gnu/gtk-2.0/modules/libgtk-vector-screenshot.so",host-name="/usr/lib/x86_64-linux-gnu/gtk-2.0/modules/libgtk-vector-screenshot.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="/usr/lib/x86_64-linux-gnu/gtk-2.0/2.10.0/engines/libmurrine.so",target-name="/usr/lib/x86_64-linux-gnu/gtk-2.0/2.10.0/engines/libmurrine.so",host-name="/usr/lib/x86_64-linux-gnu/gtk-2.0/2.10.0/engines/libmurrine.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="/usr/lib/x86_64-linux-gnu/gio/modules/libgvfsdbus.so",target-name="/usr/lib/x86_64-linux-gnu/gio/modules/libgvfsdbus.so",host-name="/usr/lib/x86_64-linux-gnu/gio/modules/libgvfsdbus.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="/usr/lib/x86_64-linux-gnu/gvfs/libgvfscommon.so",target-name="/usr/lib/x86_64-linux-gnu/gvfs/libgvfscommon.so",host-name="/usr/lib/x86_64-linux-gnu/gvfs/libgvfscommon.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="/lib/x86_64-linux-gnu/libudev.so.1",target-name="/lib/x86_64-linux-gnu/libudev.so.1",host-name="/lib/x86_64-linux-gnu/libudev.so.1",symbols-loaded="0",thread-group="i1"
=thread-created,id="2",group-id="i1"
~"[New Thread 0x7fffef198700 (LWP 11923)]\n"
*running,thread-id="2"
=thread-created,id="3",group-id="i1"
~"[New Thread 0x7fffee997700 (LWP 11924)]\n"
*running,thread-id="3"
=library-loaded,id="/usr/lib/x86_64-linux-gnu/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.so",target-name="/usr/lib/x86_64-linux-gnu/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.so",host-name="/usr/lib/x86_64-linux-gnu/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="/usr/lib/x86_64-linux-gnu/librsvg-2.so.2",target-name="/usr/lib/x86_64-linux-gnu/librsvg-2.so.2",host-name="/usr/lib/x86_64-linux-gnu/librsvg-2.so.2",symbols-loaded="0",thread-group="i1"
=library-loaded,id="/usr/lib/x86_64-linux-gnu/libcroco-0.6.so.3",target-name="/usr/lib/x86_64-linux-gnu/libcroco-0.6.so.3",host-name="/usr/lib/x86_64-linux-gnu/libcroco-0.6.so.3",symbols-loaded="0",thread-group="i1"
=library-loaded,id="/usr/lib/x86_64-linux-gnu/libxml2.so.2",target-name="/usr/lib/x86_64-linux-gnu/libxml2.so.2",host-name="/usr/lib/x86_64-linux-gnu/libxml2.so.2",symbols-loaded="0",thread-group="i1"
=library-loaded,id="/usr/lib/x86_64-linux-gnu/libicuuc.so.55",target-name="/usr/lib/x86_64-linux-gnu/libicuuc.so.55",host-name="/usr/lib/x86_64-linux-gnu/libicuuc.so.55",symbols-loaded="0",thread-group="i1"
=library-loaded,id="/usr/lib/x86_64-linux-gnu/libicudata.so.55",target-name="/usr/lib/x86_64-linux-gnu/libicudata.so.55",host-name="/usr/lib/x86_64-linux-gnu/libicudata.so.55",symbols-loaded="0",thread-group="i1"
=breakpoint-modified,bkpt={number="8",type="breakpoint",disp="keep",enabled="y",addr="0x000000000041eda1",func="$main",file="subrip.lpr",fullname="/home/arlen/appdev/subrip-laz4/subrip.lpr",line="44",thread-groups=["i1"],times="1",original-location="/home/arlen/appdev/subrip-laz4/subrip.lpr:44"}
~"\n"
~"Thread 1 \"subrip\" hit Breakpoint 8, $main () at subrip.lpr:44\n"
~"44\t  Application.CreateForm(TFormVideoViewer, FormVideoViewer);                       //unit21\n"

. . . here we get to creating the FormVideoViewer.  I dropped the Mplayer control onto the form.

The code that I use in FormVideoViewer is:

procedure TFormVideoViewer.FormCreate(Sender: TObject);
begin
  VideoOpen := false;//no Video loaded
  PanelVideo.DoubleBuffered := true;

  . . . . . . .

  MPlayerControl1.Volume := 50;

  If Not MPlayerControl1.FindMPlayerPath Then
  begin
    {$IFDEF WINDOWS}
    MPlayerControl1.MPlayerPath :=
      IncludeTrailingBackslash(ExtractFileDir(Application.ExeName)) +
      IncludeTrailingBackSlash('mplayer') + 'mplayer' + GetExeExt;
    {$ELSE}
    MPlayerControl1.MPlayerPath :=
      IncludeTrailingBackslash(ExtractFileDir(Application.ExeName)) +
      IncludeTrailingBackSlash('mplayer') + 'mplayer';
    {$ENDIF}
  end;

  {$IFDEF Linux}
  MPlayerControl1.StartParam := '-vo x11 -zoom -fs';
  {$else} {$IFDEF Windows}
  MPlayerControl1.StartParam := '-vo direct3d -nofontconfig';
  {$ENDIF}
  {$ENDIF}

  CboStartParams.Text := MPlayerControl1.StartParam;

  PopulateCommands(False);
end;   

My debugging goes from this Form Create constructor down to line 537 of MPlayerCrtl. When it gets to that line there follows the line in controlcanvas.inc line 23:  if FControl <> AControl then FreeHandle;  FControl := AControl.  From here it crashes.  I've attached my debugging log file  trimmed down to run from the above down line 23 in controlcanvas.inc.

I will change the code and see what happens.

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1269
Re: MPlayer Access Violation
« Reply #4 on: April 09, 2016, 07:00:10 pm »
That code looks pretty similar to the FullFeatured demo, which is what I used to test under Ubuntu (MINT).  Could you do me a favour?  Compile and run that?  See if the problem reproduces there?

If that works, we have a baseline to find the difference.  If not, then I'm struggling.  Certainly the logs imply your creation steps are fine... 
Lazarus Trunk/FPC latest fixes on Windows 11
  I'm getting old and stale.  Slowly getting used to git, I'll get there...

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1269
Re: MPlayer Access Violation
« Reply #5 on: April 09, 2016, 07:06:52 pm »
I see I left the following notes in the code...
Code: [Select]
{
TODO
              EXTENSIVE TESTING UNDER LINUX
                - Tested under Linus Mint 16 (MATE) with mplayer installed (not mplayer2)
              Consider descending control from TGraphicControl (instead of creating FCanvas)
}

Both seem relevant to your case, so thanks for the additional testing...
Lazarus Trunk/FPC latest fixes on Windows 11
  I'm getting old and stale.  Slowly getting used to git, I'll get there...

abtaylr

  • Full Member
  • ***
  • Posts: 107
Re: MPlayer Access Violation
« Reply #6 on: April 09, 2016, 10:35:36 pm »
I compiled the full featured example.  It went without a hitch.  I tried running commands on the left side of the screen, but nothing showed up. Perhaps the font is set to black.  The video I opened worked fine, no sound though.  I looked at the font, it was set to black so I recompiled and the log commands showed up fine.

I used the example code modifying where I needed.  Since my original code was specific for windows, I removed all of the Windows specific stuff, added in MPlayer, then reconnected all of my existing controls.  In my case I have a separate form for the command input, although I added on TFormVideoViewer the command dropdown list from the example which then sends the output to the other form.

With the change in

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1269
Re: MPlayer Access Violation
« Reply #7 on: April 09, 2016, 10:40:24 pm »
Sweet.  Ignore everything I've said before now then - no need to comment out that code.

The issue is not in the TCustomMPlayerControl component, but in your project - something has gone wrong there.  Troubleshooting that is going to be harder working remotely.  Any chance you can Publish your project and post it here (or email to mike.cornflake@gmail.com?)  (Lazarus - Projects - Publish Project)

I'll have a look and get back to you in around 24 hours...
Lazarus Trunk/FPC latest fixes on Windows 11
  I'm getting old and stale.  Slowly getting used to git, I'll get there...

abtaylr

  • Full Member
  • ***
  • Posts: 107
Re: MPlayer Access Violation
« Reply #8 on: April 09, 2016, 10:42:35 pm »
Okay, I'll email it to you.

abtaylr

  • Full Member
  • ***
  • Posts: 107
Re: MPlayer Access Violation
« Reply #9 on: April 10, 2016, 04:56:52 am »
Ok, I added back the code commented out and I am back to my previous error.  If I F7 through the code, I seem to dodge the bullet sometimes, but F9 crashes GDB right at that point.

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1269
Re: MPlayer Access Violation
« Reply #10 on: April 10, 2016, 01:17:32 pm »
Quote
I seem to dodge the bullet sometimes

We've established that it's not  TMPlayerControl.  That works in the test harness, and you're intending on using in a similar manner in your own code.

This tells me this is one of those cases where the symptoms don't tell the full story.  Symptom: Crash in MPlayerControl.  But new information is that you dodge the bullet sometimes.  That almost always means memory and pointers.

As sent via email: Your code contains the following
Code: [Select]
procedure TFormVideoViewer.FormDestroy(Sender: TObject);
Begin
  ...
  Close;
  Free;     
End;

and

Code: [Select]
procedure TFormMPlayerCommands.FormClose(Sender : TObject;
  var CloseAction : TCloseAction);
begin
  FormMPlayerCommands.Free;
end;

I lack the skills to explain why this is bad, so have reposted here so others can explain.

But because of this, something will go wrong everytime you free a form.  And my experience back in D5 (when I did exactly the same thing) is that the symptoms aren't necessarily going to make sense.  Don't know about Lazarus/fpc because this is one of those things that you don't make the same mistake twice :-)

There's another, subtler, issue with the above code as well.   In your form code, you consistently reference the current form by variable name.  (ie In TFormMPlayerCommands.FormClose, you reference FormMPlayerCommands).

This is only going to work if you can guarantee that there will only ever be a single instance of that form at one time, and that you can guarantee this variable correctly references this code.

Really, you should be calling Self.

I note that all your forms are auto-created in the main Project.  This usually means that you expect each form to be alive for the entire duration of the project.  Instead you're attempting to free each form as it closes.  Depending upon how you're creating or displaying your forms, this may work, but I suspect it isn't.  This is why I've asked you for more of your project code, or at least your main form. 

What I *think* is happening is that in the main form you attempt to display the form, either by calling FormVideoViewer.Show (which will only work the once, because when you close that form the first time it free's itself - the second time you're going to encounter issues) or instead by creating the form anew by some variation of Application.CreateForm(TFormVideoViewer, FormVideoViewer);  And this second form won't work reliably either, because the first time you call it, you will now have two instances of TFormVideoViewer in memory.  The one autocreated by the project, and the one you've created.  Your second form will overwrite the value of FormVideoViewer, and you'll have lost all reference to the first form. 

But I may be guessing wrong (my success rate on guesses over the past few days has been alarming low - I'm working 12 hour days, and have been now for 6 weeks - I'm more than ready for my current project to be over). 
Lazarus Trunk/FPC latest fixes on Windows 11
  I'm getting old and stale.  Slowly getting used to git, I'll get there...

abtaylr

  • Full Member
  • ***
  • Posts: 107
Re: MPlayer Access Violation
« Reply #11 on: April 12, 2016, 02:30:46 am »
Oh, I see what you mean about the forms.  Yes, all of them are initially created, but not shown until called.  My intention was to keep them lying in wait and suddenly appear as needed.  For example, if Unit03 is open along with Unit01, but you want to open Unit05, then Unit03 needs to close, but not be destroyed because it needs to re-appear again.  It is the same way for most of the other forms as well. 

I will re-think how to deal with that issue.  Thanks.

abt

 

TinyPortal © 2005-2018