Recent

Author Topic: TMainMenuComponentEditor: Invalid floating point operation  (Read 3257 times)

linuxfan

  • Jr. Member
  • **
  • Posts: 57
TMainMenuComponentEditor: Invalid floating point operation
« on: June 20, 2019, 07:36:48 am »
Hi all,

I converted a delphi project to lazarus under linux. Convertion went acceptably smooth, the program runs and all works but... at a certain point I decided to modify my main menu. The menu editor does not show up and, instead, this message rises up:

Class component editor "TMainMenuComponentEditor" raised the error "Invalid floating point operation"

(my message is in italian, I quote it in english - maybe inaccurate).

I also have a TPopupMenu which works flawlessly; I've take a look at the LFM file and it has nothing strange in it, the two menus (main and popup) are in there.

What the heck? What could I try? Of course I can edit mainmenu by hand in the LFM... but this is strage problem!


EganSolo

  • Sr. Member
  • ****
  • Posts: 290
Re: TMainMenuComponentEditor: Invalid floating point operation
« Reply #1 on: July 19, 2019, 02:01:33 am »
Hi Linuxfan,

Quick question: Have you tested your app in non-debug mode, or running outside the IDE? This would help determine if it's a debugger issue or bug of the menu component.

Next: Did you try a divide-and-conquer approach where you'd start by removing half of the menu entries and run it to see if you've got the same problem? Using this method might help you hone down the area of the error.

Egan.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: TMainMenuComponentEditor: Invalid floating point operation
« Reply #2 on: July 19, 2019, 07:17:59 am »
Egan: The problem seems to be with the designer, not at runtime.

linuxfan, try a simple trick: cut and paste the menu (the component in the form, in the designer). That should trigger a "test" of the menu (to see if it can be safely pasted as a component)  and should allow you to check where the problem (if any) was--by comparing the "old" and "new" menus.
« Last Edit: July 19, 2019, 07:20:52 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

EganSolo

  • Sr. Member
  • ****
  • Posts: 290
Re: TMainMenuComponentEditor: Invalid floating point operation
« Reply #3 on: July 19, 2019, 08:25:07 am »
By cut and paste: did you mean the menu component on the form?
If so, I've cut and pasted the menu on the same form. I've also copied and pasted on the same form and then I've copied and pasted on another form and I've not encountered that bug.

Have you tried simplifying the menu and trying again?

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: TMainMenuComponentEditor: Invalid floating point operation
« Reply #4 on: July 19, 2019, 09:49:26 am »
How did you do the conversion of the Delphi project to Lazarus? With the converter in the "Tools menu? I tried it with a sample project, but there were several places that I had to rework manually (maybe because I simply do no use the converter very often). In the end, however, the converted project behaves normally, in particular the menu editor.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: TMainMenuComponentEditor: Invalid floating point operation
« Reply #5 on: July 19, 2019, 12:45:53 pm »
By cut and paste: did you mean the menu component on the form?
If so, I've cut and pasted the menu on the same form. I've also copied and pasted on the same form and then I've copied and pasted on another form and I've not encountered that bug.

Yes, I meant that, although it was meant for the OP :). There is no reason for it to give problems on a normal Lazarus project but it may help locate errors in converted or manualy added definitions.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

linuxfan

  • Jr. Member
  • **
  • Posts: 57
Re: TMainMenuComponentEditor: Invalid floating point operation
« Reply #6 on: August 05, 2019, 06:47:38 pm »
Sorry all for the long delay before this post: seeing that nobody replied, I relaxed my checks in the forum.

As said in my original post, the programs runs fine, it is the menu designer that does not. Trying to visually edit the main menu rises the error (I solved by hand editing). There is also a popup menu - no issue.

Yes, I converted a project from delphi, and I know that some hand work is needed - no problem.

I will try to cut and paste the menu component, the I will post my results.

Thanks all for now.

linuxfan

  • Jr. Member
  • **
  • Posts: 57
Re: TMainMenuComponentEditor: Invalid floating point operation
« Reply #7 on: August 08, 2019, 07:01:15 am »
Hello,

here I am again with results.

Quote
> try a simple trick: cut and paste the menu
I tried cut & paste and also copy & paste; both succeded, but the pasted
components still raise the error if I try to edit them.

For your reference, I paste the textual content of the menu:

object MainMenu1: TMainMenu
  left = 81
  top = 201
  object Openfile1: TMenuItem
    Caption = '&Open file...'
    OnClick = btOpenClick
  end
  object ShowHidePanel: TMenuItem
    Caption = '  ^^vv  '
    OnClick = ShowHidePanelClick
  end
  object File1: TMenuItem
    Caption = '&File'
    object Open1: TMenuItem
      Caption = '&Open...'
      ShortCut = 16463
      OnClick = btOpenClick
    end
    object Browser1: TMenuItem
      Caption = '&Browser...'
      ShortCut = 16450
      OnClick = sbBrowserClick
    end
    object N5: TMenuItem
      Caption = '-'
    end
    object Openwithalt11: TMenuItem
      Caption = 'Open with alt &1'
      ShortCut = 16433
      OnClick = Openwithalternateplayer1Click
    end
    object Openwithalt21: TMenuItem
      Caption = 'Open with alt &2'
      ShortCut = 16434
      OnClick = Openwithalternateplayer2Click
    end
    object Openwithalt31: TMenuItem
      Caption = 'Open with alt &3'
      ShortCut = 16435
      OnClick = Openwithalt31Click
    end
    object Openwithalt41: TMenuItem
      Caption = 'Open with alt &4'
      ShortCut = 16436
      OnClick = Openwithalt41Click
    end
    object N12: TMenuItem
      Caption = '-'
    end
    object Duplicatethiswindow2: TMenuItem
      Caption = 'Duplicate this window'
      ShortCut = 16452
      OnClick = Duplicatethiswindow1Click
    end
    object N6: TMenuItem
      Caption = '-'
    end
    object mnMovefileto: TMenuItem
      Caption = '&Move file to...'
      ShortCut = 49229
      OnClick = mnMovefiletoClick
    end
    object Deletevideofile1: TMenuItem
      Caption = 'Delete videofile...'
      ShortCut = 49220
      OnClick = sbDeleteClick
    end
    object N4: TMenuItem
      Caption = '-'
    end
    object Exit1: TMenuItem
      Caption = 'E&xit'
      ShortCut = 16472
      OnClick = Exit1Click
    end
  end
  object Zoom1: TMenuItem
    Caption = '&Zoom'
    object N1x1: TMenuItem
      Caption = '1:1'
      OnClick = N1x1Click
    end
    object N8: TMenuItem
      Caption = '-'
    end
    object N141: TMenuItem
      Caption = '1/4'
      OnClick = N141Click
    end
    object N121: TMenuItem
      Caption = '1/2'
      OnClick = N121Click
    end
    object N9: TMenuItem
      Caption = '-'
    end
    object N15x1: TMenuItem
      Caption = '1.5x'
      OnClick = N15x1Click
    end
    object N2x1: TMenuItem
      Caption = '2x'
      OnClick = N2x1Click
    end
  end
  object Aspect1: TMenuItem
    Caption = '&Aspect'
    object N112: TMenuItem
      Caption = 'Original'
      ShortCut = 112
      OnClick = N111Click
    end
    object N432: TMenuItem
      Caption = '4:3'
      ShortCut = 114
      OnClick = N431Click
    end
    object N1692: TMenuItem
      Caption = '16:9'
      ShortCut = 120
      OnClick = N1691Click
    end
    object Freeresize1: TMenuItem
      Caption = 'Free resize'
      ShortCut = 116
      OnClick = Adapttowindow1Click
    end
    object N7: TMenuItem
      Caption = '-'
    end
    object Adjust1: TMenuItem
      Caption = '&Adjust...'
      ShortCut = 16449
      OnClick = Videoadjust1Click
    end
  end
  object Other1: TMenuItem
    Caption = 'Ot&her'
    object mnLoop: TMenuItem
      AutoCheck = True
      Caption = 'Loop'
    end
    object mnConfirm: TMenuItem
      AutoCheck = True
      Caption = 'Confirm &Deletions'
      Checked = True
    end
    object N11: TMenuItem
      Caption = '-'
    end
    object Options2: TMenuItem
      Caption = 'Doriplayer &options...'
      OnClick = SpeedButton1Click
    end
    object Infos2: TMenuItem
      Caption = '&Info''s...'
      OnClick = btInfoClick
    end
    object N14: TMenuItem
      Caption = '-'
    end
    object Sendcommandtomplayer1: TMenuItem
      Caption = 'Send command to mplayer...'
      OnClick = Sendcommandtomplayer1Click
    end
  end
  object N10: TMenuItem
    Caption = '-'
  end
  object Previous1: TMenuItem
    Caption = '< &Prev'
    OnClick = Previous1Click
  end
  object Next1: TMenuItem
    Caption = '&Next >'
    OnClick = sbNextClick
  end
end


howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: TMainMenuComponentEditor: Invalid floating point operation
« Reply #8 on: August 08, 2019, 04:53:38 pm »
Code: Pascal  [Select][+][-]
  1. ...
  2.     object Sendcommandtomplayer1: TMenuItem
  3.       Caption = 'Send command to mplayer...'
  4.       OnClick = Sendcommandtomplayer1Click
  5.     end
  6.   end
  7.   object N10: TMenuItem
  8.     Caption = '-'
  9.   end
  10.   object Previous1: TMenuItem
  11.     Caption = '< &Prev'
  12.     OnClick = Previous1Click
  13.   end
  14.   object Next1: TMenuItem
  15.     Caption = '&Next >'
  16.     OnClick = sbNextClick
  17.   end
  18. end
  19.  
Your .lfm is corrupt.
Notice how the last three objects are orphaned, with an "end" above their listing that should not be there, because these objects should be enclosed by that "end" and not preceded by it.
Unfortunately it is often hard, if not impossible, to edit large and complex .lfm files using the Lazarus editor, because although it provides ultra-helpful red highlights for paired items
Code: Pascal  [Select][+][-]
  1. object...end
the designer also caches edits and can do various unexpected changes behind your back; and sometimes it incorrectly reverts changes you try to make.
You can try to edit the .lfm outside the Lazarus IDE. If you are cunning, you may be able to refactor the .lfm data so it is correct.
But it is not for the faint-hearted.

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: TMainMenuComponentEditor: Invalid floating point operation
« Reply #9 on: August 08, 2019, 06:24:52 pm »
I pasted your menu lfm extract into the lfm file of a form with an empty TMainMenu component. The menu does show up in Lazarus, and when I double-click on the TMainmenu component to open the menu designer I do get the "Divide by 0" error.

Then I played with the menu and found that when I replace the '-' of item N10 by something else like 'x' the menu editor is fixed and opens correctly. Now I see that N10 is a separator in the top-level menu. It looks as if this case is not supported. To test I created a new form with a MainMenu and added three top-level items; in the Object Inspector I changed the caption of the middle item to '-'. Double-click on the MainMenu component again --> boom: "Divide by 0" again. So, the issue is reproducible, and I think this is worth a bug report...

If you want a vertical separator in the top level menu use a '|' as separator - this does not kill the menu editor.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: TMainMenuComponentEditor: Invalid floating point operation
« Reply #10 on: August 08, 2019, 11:15:23 pm »
My earlier observation is clearly incorrect. The lfm is not corrupt, but simply invalid on some non-Windows platforms.

The Lazarus menu designer introduced in early 2016  actually prevented insertion of a '-' separator item in a top-level menu.
The menu designer has since been simplified, improved and extensively refactored (mostly by Ondrej), and I think this feature preventing top-level separators has been omitted.
IIRC this is a widgetset issue - some operating systems allow top-level menu separators, others crash or become unstable if they encounter such.
But it is difficult to guard against editing of an .lfm file to insert such a thing, though not so difficult to prevent you doing it via the menu designer.



 

TinyPortal © 2005-2018