Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError while using with Starling #71

Open
rjdesignz opened this issue May 10, 2014 · 28 comments
Open

TypeError while using with Starling #71

rjdesignz opened this issue May 10, 2014 · 28 comments

Comments

@rjdesignz
Copy link

Hi,

I am getting the following error when initializing GesTouch in my Starling project:

TypeError: Error #1034: Type Coercion failed: cannot convert to org.gestouch.core.IInputAdapter.

Any idea what might be the issue?

@fljot
Copy link
Owner

fljot commented May 11, 2014

I guess you're using new buggy compiler and having issue with ||= operator.
Solution: use full transcription:

if (!obj) obj = ...;

See
http://forum.starling-framework.org/topic/gestouch-%e2%80%94-multitouch-gestures-for-starling-and-classic-displaylist/page/2#post-11689

@pablolemosassis
Copy link

Hey fljot, I am getting:
Type Coercion failed: cannot convert Function to org.gestouch.core.GestureState.
When doing
"doubleTap = new TapGesture(_botaoGo);"
"_botaoGo" is a feathers component.

Tryed everything on this thread you mentioned with no luck.
Any thoughts?

@fljot
Copy link
Owner

fljot commented Jan 3, 2015

@Pablocabana whaaaat, no, that's something new. Error stack trace maybe? Give me something.

@pablolemosassis
Copy link

This stack bellow is what I get as soon as I call
doubleTap = new TapGesture(_botaoGo); [Visualizer.as:44]
I am using feathers 2.0.

////

TypeError: Error #1034: Type Coercion failed: cannot convert Function to org.gestouch.core.GestureState.
at org.gestouch.core::GestureState/setValidNextStates()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/org/gestouch/core/GestureState.as:68]
at org.gestouch.core::GestureState$/_initClass()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/org/gestouch/core/GestureState.as:48]
at org.gestouch.core::GestureState$cinit()
at global$init()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/org/gestouch/core/GestureState.as:10]
at org.gestouch.gestures::Gesture()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/org/gestouch/gestures/Gesture.as:180]
at org.gestouch.gestures::AbstractDiscreteGesture()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/org/gestouch/gestures/AbstractDiscreteGesture.as:20]
at org.gestouch.gestures::TapGesture()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/org/gestouch/gestures/TapGesture.as:35]
at caostar.sigilizer.screens::Visualizer/initializeHandler()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/caostar/sigilizer/screens/Visualizer.as:44]
at starling.events::EventDispatcher/invokeEvent()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/events/EventDispatcher.as:146]
at starling.events::EventDispatcher/dispatchEvent()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/events/EventDispatcher.as:117]
at starling.display::DisplayObject/dispatchEvent()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/display/DisplayObject.as:398]
at starling.events::EventDispatcher/dispatchEventWith()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/events/EventDispatcher.as:195]
at feathers.core::FeathersControl/initializeInternal()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/feathers/core/FeathersControl.as:2031]
at feathers.core::FeathersControl/feathersControl_addedToStageHandler()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/feathers/core/FeathersControl.as:2086]
at starling.events::EventDispatcher/invokeEvent()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/events/EventDispatcher.as:146]
at starling.events::EventDispatcher/dispatchEvent()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/events/EventDispatcher.as:117]
at starling.display::DisplayObject/dispatchEvent()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/display/DisplayObject.as:398]
at starling.display::DisplayObjectContainer/broadcastEvent()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/display/DisplayObjectContainer.as:379]
at starling.display::DisplayObjectContainer/broadcastEventWith()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/display/DisplayObjectContainer.as:389]
at starling.display::DisplayObjectContainer/addChildAt()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/display/DisplayObjectContainer.as:135]
at starling.display::DisplayObjectContainer/addChild()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/display/DisplayObjectContainer.as:106]
at feathers.controls::ScreenNavigator/showScreen()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/feathers/controls/ScreenNavigator.as:462]
at Function/()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/feathers/controls/ScreenNavigator.as:793]
at starling.events::EventDispatcher/invokeEvent()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/events/EventDispatcher.as:146]
at starling.events::EventDispatcher/dispatchEvent()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/events/EventDispatcher.as:117]
at starling.display::DisplayObject/dispatchEvent()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/display/DisplayObject.as:398]
at starling.events::EventDispatcher/dispatchEventWith()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/events/EventDispatcher.as:195]
at caostar.sigilizer.screens::SigilForm/button_Go()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/caostar/sigilizer/screens/SigilForm.as:117]
at starling.events::EventDispatcher/invokeEvent()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/events/EventDispatcher.as:146]
at starling.events::EventDispatcher/dispatchEvent()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/events/EventDispatcher.as:117]
at starling.display::DisplayObject/dispatchEvent()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/display/DisplayObject.as:398]
at starling.events::EventDispatcher/dispatchEventWith()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/events/EventDispatcher.as:195]
at feathers.controls::Button/trigger()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/feathers/controls/Button.as:2606]
at feathers.controls::Button/button_touchHandler()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/feathers/controls/Button.as:2698]
at starling.events::EventDispatcher/invokeEvent()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/events/EventDispatcher.as:146]
at starling.events::TouchEvent/dispatch()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/events/TouchEvent.as:174]
at starling.events::Touch/dispatchEvent()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/events/Touch.as:231]
at starling.events::TouchProcessor/processTouches()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/events/TouchProcessor.as:190]
at starling.events::TouchProcessor/advanceTime()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/events/TouchProcessor.as:135]
at starling.core::Starling/advanceTime()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/core/Starling.as:469]
at starling.core::Starling/nextFrame()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/core/Starling.as:456]
at starling.core::Starling/onEnterFrame()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/starling/core/Starling.as:660]

@fljot
Copy link
Owner

fljot commented Jan 4, 2015

@Pablocabana apparently new compiler surprises. Can you try to rewrite this loop somehow differently?
https://github.com/fljot/Gestouch/blob/master/src/org/gestouch/core/GestureState.as#L68

@pablolemosassis
Copy link

@fljot Ok, it made it. It is a type conversion error.

I changed the function from this:

private function setValidNextStates(...states):void
        {
            for each (var state:GestureState in states)
            {
                validTransitionStateMap[state] = true;
            }
        }

To this:

private function setValidNextStates(...states):void
        {
            for each (var state:* in states)
            {
                trace(state)
                validTransitionStateMap[state] = true;
            }
        }

This stack below is what the trace call returned. Im using the
Apache Flex 4.13.0 FP15.0 AIR15.0 en_US
compiler.

GestureState.RECOGNIZED
GestureState.BEGAN
GestureState.FAILED
function Function() {}
function Function() {}
function Function() {}
GestureState.POSSIBLE
function Function() {}
function Function() {}
function Function() {}
GestureState.CHANGED
GestureState.ENDED
GestureState.CANCELLED
function Function() {}
function Function() {}
function Function() {}
GestureState.CHANGED
GestureState.ENDED
GestureState.CANCELLED
function Function() {}
function Function() {}
function Function() {}
GestureState.POSSIBLE
function Function() {}
function Function() {}
function Function() {}
GestureState.POSSIBLE
function Function() {}
function Function() {}
function Function() {}
GestureState.POSSIBLE
function Function() {}
function Function() {}
function Function() {}

btw, thanks for the quick reply. My first time using the lib and was stucked on this wall.

@fljot
Copy link
Owner

fljot commented Jan 5, 2015

@Pablocabana hmm state machine inside gesture might not work correctly now. Please try removing tracing the state, but rather trace states rest argument in the beginning. Just to ensure that it is something with the class static initialization and not something else.

@pablolemosassis
Copy link

@fljot ok, done that. A new trace:

GestureState.RECOGNIZED,GestureState.BEGAN,GestureState.FAILED
GestureState.POSSIBLE
GestureState.CHANGED,GestureState.ENDED,GestureState.CANCELLED
GestureState.CHANGED,GestureState.ENDED,GestureState.CANCELLED
GestureState.POSSIBLE
GestureState.POSSIBLE
GestureState.POSSIBLE

Than i tried to do this:

private function setValidNextStates(...states):void
        {
            trace(states);
            trace("states.length outside the loop: " + states.length);
            for each (var state:* in states)
            {
                trace("states.length inside the loop: " + states.length);
                validTransitionStateMap[state] = true;
            }
        }

Oddly, got this:

GestureState.RECOGNIZED,GestureState.BEGAN,GestureState.FAILED
states.length outside the loop: 3
states.length inside the loop: 3
states.length inside the loop: 3
states.length inside the loop: 3
states.length inside the loop: 3
states.length inside the loop: 3
states.length inside the loop: 3
GestureState.POSSIBLE
states.length outside the loop: 1
states.length inside the loop: 1
states.length inside the loop: 1
states.length inside the loop: 1
states.length inside the loop: 1
GestureState.CHANGED,GestureState.ENDED,GestureState.CANCELLED
states.length outside the loop: 3
states.length inside the loop: 3
states.length inside the loop: 3
states.length inside the loop: 3
states.length inside the loop: 3
states.length inside the loop: 3
states.length inside the loop: 3
GestureState.CHANGED,GestureState.ENDED,GestureState.CANCELLED
states.length outside the loop: 3
states.length inside the loop: 3
states.length inside the loop: 3
states.length inside the loop: 3
states.length inside the loop: 3
states.length inside the loop: 3
states.length inside the loop: 3
GestureState.POSSIBLE
states.length outside the loop: 1
states.length inside the loop: 1
states.length inside the loop: 1
states.length inside the loop: 1
states.length inside the loop: 1
GestureState.POSSIBLE
states.length outside the loop: 1
states.length inside the loop: 1
states.length inside the loop: 1
states.length inside the loop: 1
states.length inside the loop: 1
GestureState.POSSIBLE
states.length outside the loop: 1
states.length inside the loop: 1
states.length inside the loop: 1
states.length inside the loop: 1
states.length inside the loop: 1

@fljot
Copy link
Owner

fljot commented Jan 5, 2015

And if you rename "states" to "args"?

@pablolemosassis
Copy link

Same thing:

GestureState.RECOGNIZED,GestureState.BEGAN,GestureState.FAILED
args.length outside the loop: 3
args.length inside the loop: 3
args.length inside the loop: 3
args.length inside the loop: 3
args.length inside the loop: 3
args.length inside the loop: 3
args.length inside the loop: 3
GestureState.POSSIBLE
args.length outside the loop: 1
args.length inside the loop: 1
args.length inside the loop: 1
args.length inside the loop: 1
args.length inside the loop: 1
GestureState.CHANGED,GestureState.ENDED,GestureState.CANCELLED
args.length outside the loop: 3
args.length inside the loop: 3
args.length inside the loop: 3
args.length inside the loop: 3
args.length inside the loop: 3
args.length inside the loop: 3
args.length inside the loop: 3
GestureState.CHANGED,GestureState.ENDED,GestureState.CANCELLED
args.length outside the loop: 3
args.length inside the loop: 3
args.length inside the loop: 3
args.length inside the loop: 3
args.length inside the loop: 3
args.length inside the loop: 3
args.length inside the loop: 3
GestureState.POSSIBLE
args.length outside the loop: 1
args.length inside the loop: 1
args.length inside the loop: 1
args.length inside the loop: 1
args.length inside the loop: 1
GestureState.POSSIBLE
args.length outside the loop: 1
args.length inside the loop: 1
args.length inside the loop: 1
args.length inside the loop: 1
args.length inside the loop: 1
GestureState.POSSIBLE
args.length outside the loop: 1
args.length inside the loop: 1
args.length inside the loop: 1
args.length inside the loop: 1
args.length inside the loop: 1

@pablolemosassis
Copy link

This is how I am using now and it is working fine:

private function setValidNextStates(...states):void
        {
            for each (var state:* in states)
            {
                if(state is Function == false)validTransitionStateMap[state] = true;
            }
        }

@fljot
Copy link
Owner

fljot commented Jan 6, 2015

@Pablocabana no-no, this is totally not cool. Better try regular for loop.

@pablolemosassis
Copy link

all right, all right! ;)

@fljot
Copy link
Owner

fljot commented Jan 6, 2015

@Pablocabana it works as expected this way, right? Should I commit fix?

@neolit123
Copy link

@Pablocabana what compiler are you using (e.g. mxmlc --version)?

(EDIT: i found the version text above)

i cannot reproduce this with multiple AS3.0 compilers (e.g. from recent AIR SDK).
the output you posted above looks very broken - especially the part where "for each" counts differently than .length.

@neolit123
Copy link

what if you update your Apache Flex SDK to the latest one - 4.13.0 is from july 2014?
the issue is not present for me with the AIR SDK.

EDIT: ^ scratch the above. 4.13.0 is the latest from Apache...

also, if you create a simple HelloWorld project (i.e. just a simple Sprite class without Starling etc) does it still occur?

@neolit123
Copy link

@Pablocabana
alright, so i've just downloaded the 4.13.0 from Apache and compiled a simple AIR 15.0.x project that includes gestouch.

then used AIR's ADL 15.0.x to launch it, but cannot reproduce the issue.

i suggest you try the HelloWorld idea, so that we can confirm that this issue only occurs for larger projects.

and also confirm to fljot if this loop works:
for (var i:uint = 0; i < states.length; i++) {
....
}

@fljot if this is some sort of a crazy VM stack bug, i'd suggest you remove setValidNextStates() and unroll the validTransitionStateMap[x] calls.

@pablolemosassis
Copy link

I will try to isolate everything later. Busy now. But for a quick test:
This:

private function setValidNextStates(...states):void
        {
            for (var i:uint = 0; i < states.length; i++)
            {
                validTransitionStateMap[i] = true;
            }
        }

Throws an error as soon as douple tap the object:
Error: You cannot change from state GestureState.POSSIBLE to state GestureState.RECOGNIZED.
at org.gestouch.gestures::Gesture/setState()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/org/gestouch/gestures/Gesture.as:466]
at org.gestouch.gestures::TapGesture/onTouchEnd()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/org/gestouch/gestures/TapGesture.as:169]
at org.gestouch.gestures::Gesture/org.gestouch.core::gestouch_internal::touchEndHandler()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/org/gestouch/gestures/Gesture.as:628]
at org.gestouch.core::GesturesManager/org.gestouch.core::gestouch_internal::onTouchEnd()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/org/gestouch/core/GesturesManager.as:309]
at org.gestouch.core::TouchesManager/org.gestouch.core::gestouch_internal::onTouchEnd()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/org/gestouch/core/TouchesManager.as:185]
at org.gestouch.input::NativeInputAdapter/mouseUpHandler()[/Users/pablo/Dropbox/Public/DrawCaostar/Apps/Sigilizer/AS3/src/org/gestouch/input/NativeInputAdapter.as:216]

But this works fine:

private function setValidNextStates(...states):void
        {
            for each (var state:* in states)
            {
                validTransitionStateMap[state] = true;
            }
        }

@neolit123
Copy link

i think it should be:
validTransitionStateMap[states[i]] = true;

because it's a Dictionary?

@pablolemosassis
Copy link

oops! my bad. Tried too quickly.
validTransitionStateMap[states[i]] = true; is the right thing.

So, my tests:

1 - That does not happen on a simple hello world without starling.
2 - This does not happen on a hello world Feathers2.0 test. This is odd. So something inside my app is causing it. I cannot share the source but I am not doing anything fancy.
So I dont know if you should commit this since I couldnt isolate the cause. :/
I will try to research deeper.

@neolit123
Copy link

you could make the bug go away even if you change the simplest of things in your project and that's because it triggers for a specific stack frame state. even if you get it stable - that's no good of a solution.

and BTW for(...i < length) is much safer than "for each (x in y)" or "for (x in y)", because if the compiler has made it so that the inbound Object becomes corrupted via something like stack frame re-alignment it can in theory receive more elements that will be just assigned as key [n]...[n+x] -
in the above case to me it looks like just some Functors from the frame or perhaps the backtrace. ".length" on the other hand will remain set and it will truncate those bogus keys.
...speculations.

but as i implied earlier - varargs is a can of worms (because it's a bit difficult to implement in a compiler) and given the function is private and the number of calls is not big - unrolling the loop and inlining the function body will be the best way to solve the issue.

@fljot
Copy link
Owner

fljot commented Jan 7, 2015

@neolit123 thanks for the participation)
I don't have enough knowledge on the internals, but, to sum up, looks like regular for (i...) loop would do the job. Do you think it's an appropriate solution?

@neolit123
Copy link

glad if i can help,

pablocabana hinted that it works, but i'm not sure he meant it (?).
but either that or inlining / unrolling the setValidNextStates() as a last resort.

@pablolemosassis
Copy link

Yeah, it works 100% fine with
for (var i:uint = 0; i < states.length; i++)

I don't have enough knowledge on the internals either and I couldnt figure it out exactly what was the cause of the problem. :/

@slaymantis
Copy link

Hi any progress on this issue?
I am using air sdk 18.0 in flash builder 4.7

If I add this code

Gestouch.inputAdapter=new NativeInputAdapter(this.stage);
var doubleTap:TapGesture=new TapGesture(appMediator);
doubleTap.numTapsRequired=2;
doubleTap.addEventListener(GestureEvent.GESTURE_RECOGNIZED, onDoubleTap);

then my error is
Type Coercion failed: cannot convert to org.gestouch.core.IInputAdapter.
at org.gestouch.core::GesturesManager/onStageAvailable()org/gestouch/core/GesturesManager.as:49

code there is:

protected function onStageAvailable(stage:Stage):void
        {
            _stage = stage;

            Gestouch.inputAdapter ||= new NativeInputAdapter(stage);
            Gestouch.addTouchHitTester(new NativeTouchHitTester(stage));
        }

@slaymantis
Copy link

I changed this line in the function onStageAvailable(stage:Stage):void

Gestouch.inputAdapter||=new NativeInputAdapter(stage);
to
Gestouch.inputAdapter=new NativeInputAdapter(stage);

and its working for me
not sure what the || is for there?

The weird thing is that the objects i drag around, scale or rotate
flicker between 2 different positions quickly
If I trace gesture.offsetX and gesture.offsetY for example
It jumps wildly between a positive and a negative number

If I comment out that code then the jump isn't as wild but it is still there

@fljot
Copy link
Owner

fljot commented Aug 30, 2015

@slaymantis I've create branch with the fix https://github.com/fljot/Gestouch/tree/features/71-fix-initialization

And in changelog you can see see how you should initialize stuff: https://github.com/fljot/Gestouch/blob/features/71-fix-initialization/CHANGELOG.md

Please try and tell me if everything works)

@fljot
Copy link
Owner

fljot commented Aug 30, 2015

@slaymantis that was about automatic initialization (that stuff in onStageAvailable() in somewhere else).
But I'm not sure what is that flickering problem you had. Anyway, try and tell me how it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants