Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Illegal instruction error from example code. #39

Closed
Lorune opened this issue May 12, 2021 · 17 comments
Closed

Illegal instruction error from example code. #39

Lorune opened this issue May 12, 2021 · 17 comments
Labels
bug Something isn't working wontfix This will not be worked on

Comments

@Lorune
Copy link

Lorune commented May 12, 2021

I am trying to use this library to operate one of our Sony Alpha-A7R III, i tried to use node-gphoto2 before, but ran into some issues with the capturing of multiple images after each other.

So i was trying out this library, however i am not even getting the simplest of examples running without getting Node.JS to throw me illegal instructions errors. I am running v14.16.1 of Node.JS at the moment.

I hope you have any points as to which direction i should take this. If you need more information please let me know and ill provide it.

My current code (one of your examples)


const { Camera, closeQuietly, GPPortType, GPCameraDriverStatus, GPCameraFileOperation, GPCameraFolderOperation, GPDeviceType } = require('@tsed/gphoto2-driver');
const camera = new Camera();

try {
    console.log('[GPDRIVER] Camera init');
    camera.initialize();

    console.log('==> abilities.model', camera.getAbilities().model);
    console.log('==> abilities.port', GPPortType[camera.getAbilities().port]);
    console.log('==> abilities.status', GPCameraDriverStatus[camera.getAbilities().status]);
    console.log('==> abilities.id', camera.getAbilities().id);
    console.log('==> abilities.library', camera.getAbilities().library);
    console.log('==> abilities.operation', camera.getAbilities().operation);
    console.log('==> abilities.fileOperations', GPCameraFileOperation[camera.getAbilities().fileOperations]);
    console.log('==> abilities.folderOperations', GPCameraFolderOperation[camera.getAbilities().folderOperations]);
    console.log('==> abilities.usbVendor', camera.getAbilities().usbVendor);
    console.log('==> abilities.usbProduct', camera.getAbilities().usbProduct);
    console.log('==> abilities.usbClass', camera.getAbilities().usbClass);
    console.log('==> abilities.usbSubclass', camera.getAbilities().usbSubclass);
    console.log('==> abilities.deviceType', GPDeviceType[camera.getAbilities().deviceType]);
    console.log('==> abilities.speed', camera.getAbilities().speed);

} catch (er) {
    console.error(er.message);
} finally {
    closeQuietly(camera);
}
[GPDRIVER] Camera init


#
# Fatal error in , line 0
# Check failed: result.second.
#
#
#
#FailureMessage Object: 0x7ffeefbfdf20
 1: 0x1001141a2 node::NodePlatform::GetStackTracePrinter()::$_3::__invoke() [/Users/terencedoets/.nvm/versions/node/v14.16.1/bin/node]
 2: 0x101007d83 V8_Fatal(char const*, ...) [/Users/terencedoets/.nvm/versions/node/v14.16.1/bin/node]
 3: 0x1004d4f6d v8::internal::GlobalBackingStoreRegistry::Register(std::__1::shared_ptr<v8::internal::BackingStore>) [/Users/terencedoets/.nvm/versions/node/v14.16.1/bin/node]
 4: 0x1001fb476 v8::ArrayBuffer::GetBackingStore() [/Users/terencedoets/.nvm/versions/node/v14.16.1/bin/node]
 5: 0x10006a17e napi_get_typedarray_info [/Users/terencedoets/.nvm/versions/node/v14.16.1/bin/node]
 6: 0x1054c8706 (anonymous namespace)::WrapPointer(Napi::Env, char*, unsigned long) [/Users/terencedoets/Projects/labelflip-control/node_modules/ref-struct-napi/node_modules/ref-napi/prebuilds/darwin-x64/node.napi.node]
 7: 0x1054c9019 (anonymous namespace)::ReadPointer(Napi::CallbackInfo const&) [/Users/terencedoets/Projects/labelflip-control/node_modules/ref-struct-napi/node_modules/ref-napi/prebuilds/darwin-x64/node.napi.node]
 8: 0x1054b55af napi_value__* Napi::details::WrapCallback<Napi::details::CallbackData<Napi::Value (*)(Napi::CallbackInfo const&), Napi::Value>::Wrapper(napi_env__*, napi_callback_info__*)::'lambda'()>(Napi::Value (*)(Napi::CallbackInfo const&)) [/Users/terencedoets/Projects/labelflip-control/node_modules/ref-napi/prebuilds/darwin-x64/node.napi.node]
 9: 0x1054b554d Napi::details::CallbackData<Napi::Value (*)(Napi::CallbackInfo const&), Napi::Value>::Wrapper(napi_env__*, napi_callback_info__*) [/Users/terencedoets/Projects/labelflip-control/node_modules/ref-napi/prebuilds/darwin-x64/node.napi.node]
10: 0x10006b94a v8impl::(anonymous namespace)::FunctionCallbackWrapper::Invoke(v8::FunctionCallbackInfo<v8::Value> const&) [/Users/terencedoets/.nvm/versions/node/v14.16.1/bin/node]
11: 0x100259848 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) [/Users/terencedoets/.nvm/versions/node/v14.16.1/bin/node]
12: 0x100258ddc v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) [/Users/terencedoets/.nvm/versions/node/v14.16.1/bin/node]
13: 0x100258542 v8::internal::Builtin_Impl_HandleApiCall(v8::internal::BuiltinArguments, v8::internal::Isolate*) [/Users/terencedoets/.nvm/versions/node/v14.16.1/bin/node]
14: 0x100a719b9 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit [/Users/terencedoets/.nvm/versions/node/v14.16.1/bin/node]
Illegal instruction: 4

I have the package installed along with gphoto2 and the gphoto lib version

$ npm view @tsed/gphoto2-driver

@tsed/[email protected] | MIT | deps: 5 | versions: 2
Node.js wrapper of C library libgphoto2 written in TypeScript
https://github.com/TypedProject/ts-gphoto2-driver/tree/production/packages/gphoto2-driver

keywords: gphoto-driver, typescript, driver, apn, reflex

dist
.tarball: https://registry.npmjs.org/@tsed/gphoto2-driver/-/gphoto2-driver-3.0.1.tgz
.shasum: 194b6dbe8ba7cfc4ed8ac2bf114ea4ba323955b6
.integrity: sha512-yfjyYmxqWlcqQBezV8kM5NTaUfshajr8YkizjiN2dR/lVfL0N9JhOZ/TBfw8gyAFd8NSVZaGR2VnWYlSpb5C/g==
.unpackedSize: 175.6 kB

dependencies:
@tsed/core: 6.43.4         @tsed/gphoto2-core: 3.0.1  @tsed/logger: 5.13.2       source-map-support: 0.5.19 tslib: 2.2.0               

maintainers:
- romakita <[email protected]>

dist-tags:
latest: 3.0.1  

published 3 weeks ago by romakita <[email protected]>

Brew package installed info

$ brew info libgphoto2
libgphoto2: stable 2.5.27 (bottled), HEAD
Gphoto2 digital camera library
http://www.gphoto.org/proj/libgphoto2/
/usr/local/Cellar/libgphoto2/2.5.27 (129 files, 96MB) *
  Poured from bottle on 2021-04-30 at 15:58:32
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/libgphoto2.rb
License: LGPL-2.1-or-later
==> Dependencies
Build: pkg-config ✔
Required: gd ✔, libtool ✔, libusb-compat ✔
==> Options
--HEAD
	Install HEAD version
==> Analytics
install: 889 (30 days), 3,637 (90 days), 14,333 (365 days)
install-on-request: 542 (30 days), 2,422 (90 days), 6,432 (365 days)
build-error: 0 (30 days)
$ npm --version
7.12.1
$ npm view nan

[email protected] | MIT | deps: none | versions: 81
Native Abstractions for Node.js: C++ header for Node 0.8 -> 14 compatibility
https://github.com/nodejs/nan#readme

dist
.tarball: https://registry.npmjs.org/nan/-/nan-2.14.2.tgz
.shasum: f5376400695168f4cc694ac9393d0c9585eeea19
.integrity: sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ==
.unpackedSize: 418.0 kB

maintainers:
- kkoopa <[email protected]>
- rvagg <[email protected]>

dist-tags:
latest: 2.14.2  

published 7 months ago by kkoopa <[email protected]>
@Romakita
Copy link
Collaborator

Romakita commented May 12, 2021

@Lorune I upgraded recently the entire project to recent dependencies. You can try with the v2: https://github.com/TypedProject/ts-gphoto2-driver/tree/v2.4.3

It's a stable released. I'm sorry about the errors related to the v3. I'll try to fix this version ASAP!

@Lorune
Copy link
Author

Lorune commented May 12, 2021

Version 2.4.3 works fine.

Thanks a lot for the swift reply, onwards to integrate it further :)

@Lorune Lorune closed this as completed May 12, 2021
@Lorune
Copy link
Author

Lorune commented May 12, 2021

Ok, so capturing a image with the following code works :

const { Camera, CameraList ,closeQuietly } = require('@typedproject/gphoto2-driver');
const camera = new Camera();

console.log('Camera =>', camera.getSummary());

const cameraFile = camera.captureImage();

cameraFile.save(path.join(__dirname, 'capture.jpeg'));

closeQuietly(cameraFile);
closeQuietly(camera);

However the example that contains :

const cameralist = new CameraList().load();

It still produces :

#
# Fatal error in , line 0
# Check failed: result.second.
#
#
#
#FailureMessage Object: 0x7ffeefbfdc20
 1: 0x1001141a2 node::NodePlatform::GetStackTracePrinter()::$_3::__invoke() [/Users/terencedoets/.nvm/versions/node/v14.16.1/bin/node]
 2: 0x101007d83 V8_Fatal(char const*, ...) [/Users/terencedoets/.nvm/versions/node/v14.16.1/bin/node]
 3: 0x1004d4f6d v8::internal::GlobalBackingStoreRegistry::Register(std::__1::shared_ptr<v8::internal::BackingStore>) [/Users/terencedoets/.nvm/versions/node/v14.16.1/bin/node]
 4: 0x1001fb476 v8::ArrayBuffer::GetBackingStore() [/Users/terencedoets/.nvm/versions/node/v14.16.1/bin/node]
 5: 0x10006a17e napi_get_typedarray_info [/Users/terencedoets/.nvm/versions/node/v14.16.1/bin/node]
 6: 0x1053b7706 (anonymous namespace)::WrapPointer(Napi::Env, char*, unsigned long) [/Users/terencedoets/Projects/labelflip-control/node_modules/@typedproject/gphoto2-driver/node_modules/ref-napi/prebuilds/darwin-x64/node.napi.node]
 7: 0x1053b8019 (anonymous namespace)::ReadPointer(Napi::CallbackInfo const&) [/Users/terencedoets/Projects/labelflip-control/node_modules/@typedproject/gphoto2-driver/node_modules/ref-napi/prebuilds/darwin-x64/node.napi.node]
 8: 0x1053ba1af napi_value__* Napi::details::WrapCallback<Napi::details::CallbackData<Napi::Value (*)(Napi::CallbackInfo const&), Napi::Value>::Wrapper(napi_env__*, napi_callback_info__*)::'lambda'()>(Napi::Value (*)(Napi::CallbackInfo const&)) [/Users/terencedoets/Projects/labelflip-control/node_modules/@typedproject/gphoto2-driver/node_modules/ref-napi/prebuilds/darwin-x64/node.napi.node]
 9: 0x1053ba14d Napi::details::CallbackData<Napi::Value (*)(Napi::CallbackInfo const&), Napi::Value>::Wrapper(napi_env__*, napi_callback_info__*) [/Users/terencedoets/Projects/labelflip-control/node_modules/@typedproject/gphoto2-driver/node_modules/ref-napi/prebuilds/darwin-x64/node.napi.node]
10: 0x10006b94a v8impl::(anonymous namespace)::FunctionCallbackWrapper::Invoke(v8::FunctionCallbackInfo<v8::Value> const&) [/Users/terencedoets/.nvm/versions/node/v14.16.1/bin/node]
11: 0x100259848 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) [/Users/terencedoets/.nvm/versions/node/v14.16.1/bin/node]
12: 0x100258ddc v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) [/Users/terencedoets/.nvm/versions/node/v14.16.1/bin/node]
13: 0x100258542 v8::internal::Builtin_Impl_HandleApiCall(v8::internal::BuiltinArguments, v8::internal::Isolate*) [/Users/terencedoets/.nvm/versions/node/v14.16.1/bin/node]
14: 0x100a719b9 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit [/Users/terencedoets/.nvm/versions/node/v14.16.1/bin/node]
Illegal instruction: 4

It is now running the 2.4.3 version.

@Lorune Lorune reopened this May 12, 2021
@Romakita
Copy link
Collaborator

Erf… i haven’t idea…

@Romakita Romakita added the bug Something isn't working label May 13, 2021
@Romakita
Copy link
Collaborator

I'll try to fix the project ASAP.

@Lorune
Copy link
Author

Lorune commented May 17, 2021

Would be much appreciated, otherwise i have to resort to a native c++ implementation. None of the available library wrappers seem to deal very well with 2 camera's.

If you need more info or help with testing just give me a message or ping me here.

@Romakita
Copy link
Collaborator

2 camera's connected ? ts-gphotodriver2 is inspired from node-gphoto2 so It's probably the same issue.

@Romakita
Copy link
Collaborator

And I haven't two camera XD

@Lorune
Copy link
Author

Lorune commented May 17, 2021

If there is anything i can do to debug this myself i don't mind helping out, but i have never worked on node modules myself that use c++ libraries, only ever interacted with those directly.

And yes it also has issues with it.

@Romakita
Copy link
Collaborator

@Lorune Sure.

The library use NAPI to wrap native C++ module with nodejs.
All gphoto function are configured and wrapped here: https://github.com/tsedio/ts-gphoto2-driver/blob/v2.4.3/src/driver/GPhoto2Driver.ts

For the cameraList, you have class that call the native wrapped method:
https://github.com/tsedio/ts-gphoto2-driver/blob/v2.4.3/src/components/CameraList.ts#L18

GPhoto2Driver.gp_camera_autodetect(this.pointer, Context.get().pointer);

This function is wrapped here:
https://github.com/tsedio/ts-gphoto2-driver/blob/v2.4.3/src/driver/modules/GPCameraModule.ts#L78

This line for example, configure the gp_camera_autodetect signature:

gp_camera_autodetect: ["int", [RefList, RefContext]],

The first index int is the returned value by the native method. NAPI will convert it to the Javascript type domain.
Then the second index is an array of argument types:

  • A pointer to a list
  • A pointer to the Context... (I don't know exactly what is it)

How I have determined this types ^^' ? By reading the official API documentation here:
http://www.gphoto.org/doc/api/gphoto2-camera_8h.html#ae7b6050bb4bc7a697f9e07253c27710f

int gp_camera_autodetect ( CameraList * list, GPContext * context)

The error is in the load method which calls different native method.
https://github.com/tsedio/ts-gphoto2-driver/blob/v2.4.3/src/components/CameraList.ts#L24

You can edit the CameraList in the node_modules and add logs to determine where come from the problems :)

Tell me if you have any question. Also, you can join us on the Slack here: https://api.tsed.io/rest/slack/tsedio/tsed

See you
Romain

@Lorune
Copy link
Author

Lorune commented May 18, 2021

I will be busy today with some other stuff but i will see if i can dedicate some time to it in the next few days.

@Romakita
Copy link
Collaborator

Sure ;)

@Romakita
Copy link
Collaborator

@Lorune I fixed the v3 version. But the napi-ref isn't fully compatible with Node.js v14

I'll try to understand the reason!

See you
Romain

@detrist
Copy link

detrist commented May 25, 2021

Not sure what error you are facing but both v2.4.3 and v3.0.3 are crashing on node v14.x. I found the following item related to my problem:
node-ffi-napi/ref-napi#54

@Romakita
Copy link
Collaborator

Yes the code crash with v14, but not with v12 when the scripts try to get camera list. And yes the error is the same.
But I don't know what can I do ^^

@detrist
Copy link

detrist commented May 25, 2021

Indeed it works on v12, I can confirm. The linked issue contains a reference for a more robust implementation of ref-napi... currently I have no time for that but later I will try to wire them into the driver and see wheter it will resolve our problem or not.

@stale
Copy link

stale bot commented Jul 24, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Jul 24, 2021
@stale stale bot closed this as completed Jul 31, 2021
@Romakita Romakita moved this to Done in Global Board Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wontfix This will not be worked on
Projects
Archived in project
Development

No branches or pull requests

3 participants