On Monday, April 25, 2016, Thomas Fischer <[email protected]> wrote:

> Hi all,
>
> For *class_* it works as expected when a nullptr is returned like:
>   MyClass* getMyClass() {
>     return nullptr; // JS value: null
>   }
>
> But for *value_array* I get back an JS array, even if a nullptr was
> returned:
>   Point2f* getPoint2f() {
>     return nullptr; // JS value: [3.5733110840282835e-43, 0]
>   }
>   //...
>   EMSCRIPTEN_BINDINGS(Foo) {
>     value_array<Point2f>("Point2f")
>             .element(&Point2f::x)
>             .element(&Point2f::y);
>   }
>
>
> It seems that *value_array* binding doesn't check against nulltptr
> beforehand, when translating it into a JS Array.
> Is it a bug or a feature? Is there anything else I can do instead of
> wrapping the Point2f value to cover the nullptr case?
>

Value objects/arrays are marshaled through embind by value -- making a copy
of the data into a JS structure -- rather than by reference/pointer, so I
don't think they're really supposed to be handling a pointer return value
like this.

Does it work the way you expect when you return a pointer to a Point2f that
does exist? If so,  embind probably _should_ handle nullptr by marshaling
to JS null, but would have to check the code to figure out what
exact mechanism is happening here.

Be warned that changing a value object on the JS side won't change the
C-side struct that your function returned a pointer to -- value
objects/arrays are best suited for immutable objects and those that you
modify through a load/store interface.

-- brion

>
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to