Problem when trying to use Type.createInstance in HXCPP

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem when trying to use Type.createInstance in HXCPP

singmajesty
I have had problems in using Type.createInstance with HXCPP. Originally I  
had thought that Type.createInstance simply did not work on HXCPP, but I  
realize now that it is more of an edge-case. However, this scenario is  
exactly what is affecting Actuate. Actuate normally supports multiple  
"actuators" which can be used to power a tween. This is accomplished by  
using Type.createInstance on either the default actuator, or a custom  
actuator that is passed into the function.


Here is some simple code I came up with which surfaced the problem:



public function new () {
       
        super ();
       
        initialize ();
       
        var target = new Sprite ();
        var duration = 1;
        var properties = { x: 100 };
       
        var instance = Type.createInstance (GenericActuator, [ target, duration,  
properties ] );
       
        trace ("Target = " + instance.target);
        trace ("Duration = " + instance.duration);
        trace ("Properties = " + instance.properties);
       
        localFunctionTest (target, duration, properties);
        staticFunctionTest (target, duration, properties);
       
}


private function localFunctionTest (target:Dynamic, duration:Float,  
properties:Dynamic):Void {
       
        var instance = Type.createInstance (GenericActuator, [ target, duration,  
properties ] );
       
        trace ("Target = " + instance.target);
        trace ("Duration = " + instance.duration);
        trace ("Properties = " + instance.properties);
       
}


public static function staticFunctionTest (target:Dynamic, duration:Float,  
properties:Dynamic):Void {
       
        var instance = Type.createInstance (GenericActuator, [ target, duration,  
properties ] );
       
        trace ("Target = " + instance.target);
        trace ("Duration = " + instance.duration);
        trace ("Properties = " + instance.properties);
       
}




In this test, GenericActuator is a simple class that sets "this.target =  
target", and so on. Running through these tests, I created an instance in  
the constructor of my application, and then I created an instance in a  
local function and a static function.

The first one works. Target will trace "Sprite 4" or whatever number its  
on, duration will trace "1" and properties will also trace correctly.  
However, when target and properties are passed to either the local or  
static functions, instance.target and instance.properties come out  
equaling 0 instead of the original object values.


Thanks!

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Problem when trying to use Type.createInstance in HXCPP

Nicolas Cannasse
Le 08/10/2011 18:09, Joshua Granick a écrit :
> I have had problems in using Type.createInstance with HXCPP. Originally
> I had thought that Type.createInstance simply did not work on HXCPP, but
> I realize now that it is more of an edge-case. However, this scenario is
> exactly what is affecting Actuate. Actuate normally supports multiple
> "actuators" which can be used to power a tween. This is accomplished by
> using Type.createInstance on either the default actuator, or a custom
> actuator that is passed into the function.

Could you try to reproduce with a single standalone code that does not
use any third party library, then try to remove each line of code that
still make the bug reproducible ? In the end this should be only 2-3
classes with a few lines, that should help you understand in which
condition the bug occur and help us to fix it quickly ;)

Best,
Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Problem when trying to use Type.createInstance in HXCPP

singmajesty
Hey Nicolas,

I should have included the GenericActuator class. I'm using the same name  
as my "real" class, but this test was performed with a stub class, like  
this:



package;


class GenericActuator {
       
        public var target:Dynamic;
        public var duration:Float;
        public var properties:Dynamic;
       
        public function new (target:Dynamic, duration:Float, properties:Dynamic) {
               
                this.target = target;
                this.duration = duration;
                this.properties = properties;
               
        }

}



This can be combined with the previous code I shared to reproduce the  
problem:



package;


class InstanceTest {


        public function new () {
               
                super ();
               
                var target = new Sprite ();
                var duration = 1;
                var properties = { x: 100 };
               
                var instance = Type.createInstance (GenericActuator, [ target, duration,  
properties ] );
               
                trace ("Target = " + instance.target);
                trace ("Duration = " + instance.duration);
                trace ("Properties = " + instance.properties);
               
                localFunctionTest (target, duration, properties);
                staticFunctionTest (target, duration, properties);
               
        }

        private function localFunctionTest (target:Dynamic, duration:Float,  
properties:Dynamic):Void {
               
                var instance = Type.createInstance (GenericActuator, [ target, duration,  
properties ] );
               
                trace ("Target = " + instance.target);
                trace ("Duration = " + instance.duration);
                trace ("Properties = " + instance.properties);
               
        }
       
        public static function staticFunctionTest (target:Dynamic,  
duration:Float, properties:Dynamic):Void {
               
                var instance = Type.createInstance (GenericActuator, [ target, duration,  
properties ] );
               
                trace ("Target = " + instance.target);
                trace ("Duration = " + instance.duration);
                trace ("Properties = " + instance.properties);
               
        }
       
}




On Sun, 09 Oct 2011 11:27:03 -0700, Nicolas Cannasse  
<[hidden email]> wrote:

> Le 08/10/2011 18:09, Joshua Granick a écrit :
>> I have had problems in using Type.createInstance with HXCPP. Originally
>> I had thought that Type.createInstance simply did not work on HXCPP, but
>> I realize now that it is more of an edge-case. However, this scenario is
>> exactly what is affecting Actuate. Actuate normally supports multiple
>> "actuators" which can be used to power a tween. This is accomplished by
>> using Type.createInstance on either the default actuator, or a custom
>> actuator that is passed into the function.
>
> Could you try to reproduce with a single standalone code that does not  
> use any third party library, then try to remove each line of code that  
> still make the bug reproducible ? In the end this should be only 2-3  
> classes with a few lines, that should help you understand in which  
> condition the bug occur and help us to fix it quickly ;)
>
> Best,
> Nicolas
>


--
Using Opera's revolutionary email client: http://www.opera.com/mail/

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Problem when trying to use Type.createInstance in HXCPP

Gamehaxe
Hi,
I have narrowed this down to a problem with the typing of the combined  
array:
class Test {

    public static function main()
    {
       // Case 1
       var properties:Dynamic = { x: 100 };
       trace([ properties,1 ]);

       // Case 2
       var d = new Array<Dynamic>();
       d.push(properties);
       d.push(1);
       trace(d);
    }
       
}


Case 1 is wrong because an Array<Int> is created, rather than an  
Array<Dynamic>.
I think this may be a problem with the type unification code.
Any comments Nicolas?

Hugh

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Problem when trying to use Type.createInstance in HXCPP

Nicolas Cannasse
Le 30/10/2011 17:38, Gamehaxe a écrit :

> Hi,
> I have narrowed this down to a problem with the typing of the combined
> array:
> class Test {
>
> public static function main()
> {
> // Case 1
> var properties:Dynamic = { x: 100 };
> trace([ properties,1 ]);
[...]
> Case 1 is wrong because an Array<Int> is created, rather than an
> Array<Dynamic>.
> I think this may be a problem with the type unification code.
> Any comments Nicolas?

A bug indeed. Fixed in r4060, thanks for reporting ;)

Best,
Nicolas

--
haXe - an open source web programming language
http://haxe.org