Embind Reference Error: "getTypeName is not defined"
Hi, I have an Issue when trying to call a embinded function. It seems to be related with the issue below, but unfortunately the thread didn't really help me.
I exported a class with Embind. In this class I have a function. It is to process some samples from audio input, so it takes a constant pointer to the float data and a unsigned int value for the sample size. So it looks something like this
void processing(const float* data, unsigned int size);
I exported it using allow_raw_pointers(), and everything compiled fine. In Javascript I can construct the object without problems.
But how exactly do I use the exported function now? As an example I created a sample block as an array, which contains just a basic sine wave. I tried calling the function like
object.processing(sineWavaData, blockSize);
But this gives me the error, that I wrote in the title.
For your information, I know the basic concept of pointers, but I am quite inexperienced with advanced pointer usage, so it would be really great, if you could help me with that :)
I get the same error. I think it is a problem with the generated JavaScript Code. It wants to display another error but this does not work
The generated code looks like this:
var UnboundTypeError=undefined;function throwUnboundTypeError(message, types) {
var unboundTypes = [];
var seen = {};
function visit(type) {
if (seen[type]) {
return;
}
if (registeredTypes[type]) {
return;
}
if (typeDependencies[type]) {
typeDependencies[type].forEach(visit);
return;
}
unboundTypes.push(type);
seen[type] = true;
}
types.forEach(visit);
throw new UnboundTypeError(message + ': ' + unboundTypes.map(getTypeName).join([', ']));
}
It crashs at the last code line with "ReferenceError: getTypeName is not defined"
I know where the error comes from in my code, because I am trying to call the embinded function with the array as the function argument while the function requires a raw pointer. So I guess that is what the error message is trying to say, but can't because of a bug in the message code.
I finally just found a viable solution for my problem. The examples with pointers I found online all included calling the functions using ccall or wrapping the function using cwrap, but as I see this is not possible for member functions, or at least I don't know how to do this (so if someone knows, please let me know). What helped me the most was this blog post or whatever it is: kapadia.github.io/emscripten/2013/09/13/emscripten-pointers-and-pointers.html But instead of cwraping/ccalling the function I wrote a simple wrapper in C++, which takes an uintptr_t as the input parameter which is the address to the array. In the wrapper I am simply creating the float* and make it point to the address. So it looks like this:
#include <stdint.h>
void ptrWrapper(uintptr_t address, unsigned int size)
{
float *ptr = reinterpret_cast<float*>(address);
testPtr(ptr, size);
}
testPtr is the actual function that takes the float* as the argument. Size is the size of the block obviously.
In Javascript I am calling the function like in the example in the blog post.
pointerTest.ptrWrapper(dataHeap.byteOffset, blockSize);
pointerTest is just an instance of the PointerTest class that contains the wrapper function.
@kripken, it looks like #3809 addressed this and #3487, but the automatic closing didn't work correctly once that pull request was merged. Can you close those two issues manually? Thanks!