Gestouch icon indicating copy to clipboard operation
Gestouch copied to clipboard

TypeError while using with Starling

Open rjdesignz opened this issue 11 years ago • 28 comments

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?

rjdesignz avatar May 10 '14 12:05 rjdesignz

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

fljot avatar May 11 '14 17:05 fljot

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?

pablolemosassis avatar Jan 03 '15 23:01 pablolemosassis

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

fljot avatar Jan 03 '15 23:01 fljot

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]

pablolemosassis avatar Jan 04 '15 17:01 pablolemosassis

@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

fljot avatar Jan 04 '15 20:01 fljot

@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.

pablolemosassis avatar Jan 04 '15 22:01 pablolemosassis

@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.

fljot avatar Jan 05 '15 15:01 fljot

@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

pablolemosassis avatar Jan 05 '15 15:01 pablolemosassis

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

fljot avatar Jan 05 '15 22:01 fljot

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 avatar Jan 06 '15 13:01 pablolemosassis

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;
            }
        }

pablolemosassis avatar Jan 06 '15 13:01 pablolemosassis

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

fljot avatar Jan 06 '15 18:01 fljot

all right, all right! ;)

pablolemosassis avatar Jan 06 '15 20:01 pablolemosassis

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

fljot avatar Jan 06 '15 20:01 fljot

@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 avatar Jan 06 '15 20:01 neolit123

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 avatar Jan 06 '15 20:01 neolit123

@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.

neolit123 avatar Jan 06 '15 21:01 neolit123

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;
            }
        }

pablolemosassis avatar Jan 06 '15 21:01 pablolemosassis

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

because it's a Dictionary?

neolit123 avatar Jan 06 '15 21:01 neolit123

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.

pablolemosassis avatar Jan 07 '15 02:01 pablolemosassis

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.

neolit123 avatar Jan 07 '15 13:01 neolit123

@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?

fljot avatar Jan 07 '15 22:01 fljot

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.

neolit123 avatar Jan 07 '15 23:01 neolit123

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. :/

pablolemosassis avatar Jan 09 '15 03:01 pablolemosassis

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 avatar Aug 22 '15 11:08 slaymantis

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

slaymantis avatar Aug 22 '15 12:08 slaymantis

@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 avatar Aug 30 '15 16:08 fljot

@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.

fljot avatar Aug 30 '15 16:08 fljot