Working lcb script in LC 8 generates error in LC 9 dp 2

LiveCode Builder is a language for extending LiveCode's capabilities, creating new object types as Widgets, and libraries that access lower-level APIs in OSes, applications, and DLLs.

Moderators: LCMark, LCfraser

Post Reply
pthirkell
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 93
Joined: Tue Nov 17, 2009 6:47 pm
Location: Wellington, New Zealand

Working lcb script in LC 8 generates error in LC 9 dp 2

Post by pthirkell » Wed Nov 23, 2016 9:26 am

When I ran my script it generated a couple of minor errors which were easily fixed. These were to do with the parsing of numeric literals which is flagged in the release notes.

But when the widget attempts to launch in the Test Window it generates the following error:

9:12 PM: Launching in Test Window
9:12 PM: Error: Community.livecode.thirkell.multicolorSVG is not valid - malformed bytecode

Any pointers towards what is going wrong and how I might fix would be appreciated.

peter-b
Posts: 182
Joined: Thu Nov 20, 2014 2:14 pm
Location: LiveCode Ltd.

Re: Working lcb script in LC 8 generates error in LC 9 dp 2

Post by peter-b » Wed Nov 23, 2016 9:28 am

I've never seen this before; please open a bug report and attach your LCB source code so that we can take a look at it! :shock:
LiveCode Open Source Team — @PeterTBBrett — peter.brett@livecode.com

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Working lcb script in LC 8 generates error in LC 9 dp 2

Post by bn » Wed Nov 23, 2016 9:36 am

I have the same problem and can't figure out what is going on.
9:32 AM: Skipping recompilation of /Users/berndnig/Desktop/turnText/module.lcm - module is up to date
9:32 AM: Launching in Test Window
9:32 AM: Error: Community.livecode.berndn.turnText is not valid - malformed bytecode
The LCB file compiles in LC 9.0 DP1 alright but not in LC 9.0 DP2

The script:

Code: Select all

/**
This widget lets you turn text horizontally. Optionally it lets you add a
 circle as the back for the text and a drop shadow.
Change text, text size, animation speed and animation on/off.
Use Properties inspector to use options.
This widget has made use of example code for transorm matrix by Trevor Devore
which he generously put up in his blog [Creating a busy Indicator]
(http://bluemangolearning.com/livecode/2015/04/
creating-a-busy-indicator-in-livecode-builder/).
Thanks Trevor for this and your other contributions to making widgets.
Code is adapted to horizontally restricted turn.
Hermann Hoch helped me with the math.

Bernd Niggemann May 2016
*/

/**
Name: foreColor
Type: property

Syntax:
set the foreColor of <widget> to <pColor>
get the foreColor of <widget>

Summary: Determines the color of the text.

Description:
Use the <foreColor> property to set the text color.
*/



/**

Name: backgroundColor
Type: property


Syntax:
set the backgroundColor of <widget> to <pColor>
get the backgroundColor of <widget>

Summary: Determines the color of the background.

Description:
Use the <backgroundColor> property to set the background color.
*/



/**
Name: hiliteColor
Type: property


Syntax:
set the hiliteColor of <widget> to <pColor>
get the hiliteColor of <widget>

Summary: Determines the color of the background circle .

Description:
Use the <hiliteColor> property to set the color of the background circle.
*/




-- declaring extension as widget, followed by identifier
widget community.livecode.berndn.turnText

use com.livecode.canvas
use com.livecode.widget
use com.livecode.engine
use com.livecode.library.widgetutils
use com.livecode.math


metadata title is "turnText"
metadata author is "Bernd Niggemann"
metadata version is "1.0.1"

metadata preferredSize is "120,120"

metadata foregroundColor.editor is "com.livecode.pi.color"
metadata foregroundColor.default is "50,50,50"
metadata foregroundColor.section is "Colors"
metadata foregroundColor.label is "Text Color"

metadata backgroundColor.editor is "com.livecode.pi.color"
metadata backgroundColor.default is "255,0,0"
metadata backgroundColor.section is "Colors"
metadata backgroundColor.label is "Background Color"

metadata hiliteColor.editor is "com.livecode.pi.color"
metadata hiliteColor.default is "225,238,187"
metadata hiliteColor.section is "Colors"
metadata hiliteColor.label is "Inner Circle"

  /**
  Syntax: set the displayText of <widget> to <pString>
  Syntax: get the displayText of <widget>

  Summary: The string displayed in the widget.

  Description:
  The <displayText> is used to set the text that is displayed by the widget. Can be set while widget is turning.
  Change the foreground color in the Properties inspector to change the color of text.
  */
 property displayText  get mDisplayText set setDisplayText
 metadata displayText.editor is "com.livecode.pi.text"
 metadata displayText.default is "Dont Ask"
 metadata displayText.label is "Displaytext"

 /**
 Syntax: set the turnText of <widget> to <pBoolean>
 Syntax: get the turnText of <widget>

 Summary: turnText set to true will let the widget rotate horizontally.

 Description:
 The <turnText> is used to animate the text by turning text horizontally.
 */
 property turnText   get mTurnText  set setTurnText

 /**
 Syntax: set the showCircle of <widget> to <pBoolean>
 Syntax: get the showCircle of <widget>

 Summary: showCircle set to true will show a circle around the text.

 Description:
 The <showCircle> is used to provide a background circle for the text.
 Change the hilited color in the Properties inspector to change the color of background circle.
 */

 property showCircle  get mShowCircle  set setShowCircle

 /**
 Syntax: set the showOuterShadow of <widget> to <pBoolean>
 Syntax: get the showOuterShadow of <widget>

 Summary: showOuterShadow set to true will show a outer shadow around the inner circle if visible or the text.

 Description:
 <showOuterShadow> is used to provide a outer shadow effect for the inner circle of for the text.
 If showCircle is false and <showOuterShadow> true then the text will aquire an outer shadow.
 <showOuterShadow> uses the hilited color in the Properties inspector which is the same as is used for text.
 */

 property showOuterShadow  get mOuterShadow  set setOuterShadow

 /**
 Syntax: set the turnSpeed of <widget> to <pNumber>
 Syntax: get the turnSpeed of <widget>

 Summary: The turnSpeed is used to slow or speed up text animation 1 being slow and 10 fast.

 Description:
 <turnSpeed> determines the increase in angle at each iteration. It is the step size of the angle increase.

 */
   property turnSpeed  get mTurnSpeed set setTurnSpeed
   metadata turnSpeed.editor	is "com.livecode.pi.number"
   metadata turnSpeed.default	is "3"
   metadata turnSpeed.step is "1"
   metadata turnSpeed.min is "1"
   metadata turnSpeed.max is "10"

 /**
 Syntax: set the sizeOfText of <widget> to <pNumber>
 Syntax: get the sizeOfText of <widget>

 Summary: sizeOfText determines point size of the text.

 Description:
 The <sizeOfText> is used to adapt the font size of the displayed text.
 */
 property sizeOfText   get mTextSize  set setTextSize
   metadata sizeOfText.editor	is "com.livecode.pi.number"
   metadata sizeOfText.default	is "16"
   metadata sizeOfText.step is "1"
   metadata sizeOfText.min is "13"
   metadata sizeOfText.max is "60"

   /**
   Syntax: set the turnAngle of <widget> to <pNumber>
   Syntax: get the turnAngle of <widget>

   Summary: The horizontal angle of the displayed text

   Description:
   The <turnAngle> is used to allow setting the horizonatal angle of text. Depending on the angle the text will appear condensed and or seen from behind.
   Useful for a static distortion of the text or scripted turning of the text.
   */
   property turnAngle 	get mTurnAngle	set setTurnAngle
    metadata turnAngle.editor	is "com.livecode.pi.number"
    metadata turnAngle.default	is "0"
    metadata turnAngle.step is  "1"
    metadata turnAngle.min is   "0"
    metadata turnAngle.max is   "360"



 public variable mMouseIsUp as Boolean
 public variable mDisplayText as String
 public variable mTurnAngle as Number
 public variable mTurnText as Boolean
 public variable mTurnSpeed as Number
 public variable mTextSize as Number
 public variable mTextFont as Font
 public variable mTextBounds as Rectangle
 public variable mShowCircle as Boolean
 public variable mOuterShadow as Boolean
 public variable mEffect as Effect
 public variable mDerivedPi as Number -- is 2*pi/360

 public handler onLoad(in pProperties as Array) returns nothing
    put pProperties["displayText"] into mDisplayText
    put pProperties["turnSpeed"] into mTurnSpeed
    put pProperties["textSize"] into mTextSize
    put pProperties["showCircle"] into mShowCircle
    put pProperties["outerShadow"] into mOuterShadow
    put 2*pi/360 into mDerivedPi
    setTextSize(mTextSize)
    makeDropShadow()
 end handler

 public handler onSave(out rProperties as Array)
    put the empty array into rProperties
    put mDisplayText into rProperties["displayText"]
    put mTurnSpeed into rProperties["turnSpeed"]
    put mTextSize into rProperties["textSize"]
    put mShowCircle into rProperties["showCircle"]
    put mOuterShadow into rProperties["outerShadow"]
    return rProperties
 end handler

 public handler onCreate()

   put 0 into mTurnAngle
   put false into mTurnText
   put true into mMouseIsUp
   put 3 into mTurnSpeed
   put 16 into mTextSize
   put 2*pi/360 into mDerivedPi
   put "Dont Ask" into mDisplayText
   setTextSize(mTextSize)

   put true into mShowCircle
   put false into mOuterShadow

   post "if the backgroundColor of me is empty then set the backgroundColor of me to 255,0,0; if the foreColor of me is empty then set the foreColor of me to 30,30,30; if the hiliteColor of me is empty then set the hiliteColor of me to 225,238,187"
   post "set the textSize of me to " & mTextSize formatted as string

   getTextDimensions()
   makeDropShadow()
 end handler

 private handler setShowCircle(pShowCircle as Boolean) returns nothing
    put pShowCircle into mShowCircle
    redraw all
 end handler

 public handler setOuterShadow(in pOuterShadow as Boolean)
   put pOuterShadow into mOuterShadow
   redraw all
 end handler

 public handler setTurnAngle(pAngle as Number)
    put pAngle into mTurnAngle
    redraw all
end handler

 private handler setDisplayText(in pDisplayText) returns nothing
   put pDisplayText into mDisplayText
   getTextDimensions()
   redraw all
 end handler

 private handler getTextDimensions()returns nothing
 put the image bounds of text mDisplayText with mTextFont into mTextBounds
 end handler

 public handler setTurnText(in pTurnBool as Boolean) returns nothing
   put pTurnBool into mTurnText
   if pTurnBool then
      schedule timer in 0.04 seconds
   end if
 end handler

 public handler setTurnSpeed(in pStepSize as Number) returns nothing
    put pStepSize into mTurnSpeed
 end handler

 public handler setTextSize(in ptextSize as Number) returns nothing
    put ptextSize into mTextSize
    put my font into mTextFont
    set the size of mTextFont to mTextSize

    getTextDimensions()
    makeDropShadow()
    redraw all
    post "set the textSize of me to " & mTextSize formatted as string
 end handler

public handler onTimer() returns nothing
   if mTurnText then
      put the maximum of 1 and (mTurnAngle + mTurnSpeed)mod 360 into mTurnAngle
      redraw all
      schedule timer in 0.025 seconds -- 25 milliseconds
   end if
end handler

 public handler onPaint()

    // to catch change of font in Properties Inspector
    if in edit mode then
      put my font into mTextFont
      put the size of my font into mTextSize
      getTextDimensions()
   end if

   variable tRect as Rectangle
   variable tHeight as Number
   put my bounds into tRect
   put my height into tHeight

   // draw a rounded rectangle
   set the paint of this canvas to my background paint
   fill rounded rectangle path of tRect with radius tHeight on this canvas

   if mOuterShadow then
      set the color of mEffect to the color of my foreground paint
      begin layer with mEffect on this canvas
   else
      begin layer on this canvas
   end if

   // Set the canvas font
   set the font of this canvas to mTextFont

    // Draw the text in the center of the target rectangle

   // this is code taken from Trevor Devore
   -- http://www.bluemangolearning.com/livecode/2015/04/creating-a-busy-indicator-in-livecode-builder/
   -- Creating a busy Indicator
   -- a big help from Hermann Hoch with streamlining the math for this special case
   variable tCenter as Point
   variable tAngle as Number
   variable tA as Number
	variable tOriginX as Number

   put point [my width / 2, my height / 2] into tCenter
   put mTurnAngle * mDerivedPi into tAngle

	put cos(tAngle) into tA -- scale the x
	put the x of tCenter into tOriginX

	variable tTransform as Transform
   put transform with matrix [tA,0,0.00001,1,(1-tA)*tOriginX,0] into tTransform

   // end code taken from Trevor

   transform this canvas by tTransform

   // branch to show inner circle or not
   if mShowCircle then
      variable tCenterEllipse as Path
      variable tMaxExtend as Number
      put (the minimum of the width of my bounds and the height of my bounds) / 2 * 0.8 into tMaxExtend
      put ellipse path centered at tCenter with radii [tMaxExtend,tMaxExtend] into tCenterEllipse
      set the paint of this canvas to my foreground paint
      set the stroke width of this canvas to 1.2
      stroke tCenterEllipse on this canvas
      set the paint of this canvas to my highlight paint
      fill tCenterEllipse on this canvas
   end if /* end show circle */

   set the paint of this canvas to my foreground paint
   fill text mDisplayText at center of tRect on this canvas

end layer on this canvas


end handler /* OnPaint */

public handler onMouseUp() returns nothing
   post "mouseUp" to my script object with [intToString(the click button)]
end handler /* onMouseUp */

public handler onMouseEnter() returns nothing
	post "mouseEnter" to my script object
end handler /* OnMouseEnter */

public handler onMouseMove()
   post "mouseMove" to my script object -- x,y are automatically sent
end handler

public handler onMouseDown()
   post "mouseDown" to my script object with [intToString(the click button)]
 end handler

public handler makeDropShadow() --returns nothing
   variable tProps as Array
   put the empty array into tProps
   put the color of my foreground paint into tProps["color"]
   put the maximum of mTextSize/7 and 3 into tProps["distance"]
   variable tSize as Number
   put 12 into tSize
   put tSize into tProps["size"]
   put tSize / 255 into tProps["spread"]
   put outer shadow effect with properties tProps into mEffect
end handler

end widget
Kind regards
Bernd

pthirkell
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 93
Joined: Tue Nov 17, 2009 6:47 pm
Location: Wellington, New Zealand

Re: Working lcb script in LC 8 generates error in LC 9 dp 2

Post by pthirkell » Wed Nov 23, 2016 10:21 am

Happy to post bug report, but frustratingly I now can't exactly replicate the error myself. It may have something to do with how I tried to fix a parsing error that was generated by the original script which worked fine in lcb 8. If I can recreate the original error (something to do with expecting a numeric list) then I will post that to get advice on how to fix the syntax. With any luck that might make the other problem go away :)

pthirkell
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 93
Joined: Tue Nov 17, 2009 6:47 pm
Location: Wellington, New Zealand

Re: Working lcb script in LC 8 generates error in LC 9 dp 2

Post by pthirkell » Wed Nov 23, 2016 10:43 am

The lcb script causing the problem is "Widget_Scale_mark4.lcb.zip" posted under "SVG in widgets - any roadmap?" in the Livecode Builder forum.

In its present form it generates an error "list must be numeric" on lines 619 and 620. Changing the code to "parse the list as number" resolves the compiler error, but leads in turn to the mysterious "malformed code" error message. Perhaps I am misunderstanding the use of string versus numeric lists in this instance?

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Working lcb script in LC 8 generates error in LC 9 dp 2

Post by [-hh] » Wed Nov 23, 2016 2:29 pm

Hi 'pthirkell' and 'bn'.

This is possibly caused by save and load procedures (the comparison to nothing is somehow 'damaged'). You could try the following.

Comment out handlers OnLoad() and OnSave().
If it runs (without 'malformed bytecode') then first enable OnSave() only, then after re-compile also OnLoad(). This way it worked for me.

@ 'pthirkell'
your handler CalculateBoundingBoxForAllPaths will work after removing two pairs of possibly misplaced brackets as follows.

Code: Select all

private handler CalculateBoundingBoxForAllPaths()
	-- find maximum drawing point of all paths to right and to bottom and use that, along with the origin (0,0) to define the effective overall bounding box for the widget
	variable tCounter as Integer
	variable tCounterString as String
	variable tPathRef as String	
	variable tBoundingBoxRect as Rectangle
	variable tPathRightIndices as List
	variable tPathBottomIndices as List
	put [] into tPathRightIndices
	put [] into tPathBottomIndices
	repeat with tCounter from 1 up to mPathCount
		format tCounter as string
		put the result into tCounterString
		put "path" & tCounterString into tPathRef	
		put the bounding box of mPathsArray["Paths"][tPathRef] into tBoundingBoxRect	
		push the right of tBoundingBoxRect onto tPathRightIndices
		push the bottom of tBoundingBoxRect onto tPathBottomIndices
	end repeat
	put the maximum value of tPathRightIndices into mMaxRight
	put the maximum value of tPathBottomIndices into mMaxBottom
end handler
shiftLock happens

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Working lcb script in LC 8 generates error in LC 9 dp 2

Post by bn » Wed Nov 23, 2016 4:50 pm

Hermann found the solution for my case

there is something with cosinus

In my script I posted above if I change in the onPaint handler

Code: Select all

	variable tA as Number
	variable tOriginX as Number

  put point [my width / 2, my height / 2] into tCenter
  put mTurnAngle * mDerivedPi into tAngle

	put cos(tAngle) into tA -- scale the x

against

Code: Select all

	variable tA as Number
	variable tA0 as Number
	variable tOriginX as Number

  put point [my width / 2, my height / 2] into tCenter
  put mTurnAngle * mDerivedPi into tAngle

  put 10^(-9) into tA0
  if the abs of tAngle < 10^(-9) then
  	   put 1 into tA
	else
  		put cos(tAngle) into tA -- scale the x
	end if
the script works in LC 9 DP2

thanks to the mathematician on call Hermann

Apparently in DP2 something changed for cos()
Kind regards
Bernd

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Working lcb script in LC 8 generates error in LC 9 dp 2

Post by [-hh] » Wed Nov 23, 2016 5:22 pm

Hi Bernd,

it's more the tA0=10^(-9) in the transform that you use. Theoretically tA0 must be exactly zero. So it's both, sin and cos (and tan and atan) that don't work correctly here. This is probably not a failure by LC but, for the current number handling, an 'unsharpness' in the library they use (?).

Pointing in the same direction:
I have often 'jumps' with movements around odd multiples of 45 degrees.

Just guessing...

Hermann

p.s. Here the 'malformed bytecode' re-appeared. And again disappeared when I commented out OnSave and OnLoad. There's possibly something going on with the bytecode of the array used by these handlers???
shiftLock happens

pthirkell
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 93
Joined: Tue Nov 17, 2009 6:47 pm
Location: Wellington, New Zealand

Re: Working lcb script in LC 8 generates error in LC 9 dp 2

Post by pthirkell » Wed Nov 23, 2016 9:18 pm

Many thanks Hermann. After your tidy up of my handler code the widget is now working properly in LC 9 dp 2. Much appreciated :)

Post Reply

Return to “LiveCode Builder”