justadudewhohacks
justadudewhohacks

Reputation: 681

Nodejs native addon weird segmentation fault

I am developing a node addon and I am facing some weird issues with segmentation faults. In the MyClass.cc I declared a struct and a NAN_METHOD as follows:

struct ComputeContext {
    int test = 1;
};

NAN_METHOD(MyClass::Foo) {
    ComputeContext ctx;
    info.GetReturnValue().Set(Nan::New(true));
}

The weird things is, when I call this method from JavaScript, the program exits and with a segmentation fault. However, if I dont initialize test, e.g. int test;, it does not crash or report a segfault. To detect segmentation faults I am using the segfault-handler package.

Maybe someone has a clue about what is going on here? As a sidenote, MyClass::Foo is a static method, not sure if that makes a difference.

Upvotes: 1

Views: 901

Answers (1)

justadudewhohacks
justadudewhohacks

Reputation: 681

Ok, turned out I had another struct called ComputeContext defined in a different .cc file. MSVC didn't throw any error and linked both files. This caused the segmentation faults when creating instances of the struct.

Upvotes: 2

Related Questions