GoogleChromeLabs / web-gphoto2

Running gPhoto2 to control DSLR cameras over USB on the Web
https://web-gphoto2.rreverser.com/
GNU Lesser General Public License v2.1
101 stars 16 forks source link

Cannot reconnect after disconnecting #8

Closed icheered closed 10 months ago

icheered commented 1 year ago

Code to reproduce the issue

This is the minimal (Svelte) reproduction:

<script lang="ts">
    import { Camera } from 'web-gphoto2';

    let camera = new Camera();

    async function connect() {
        console.log('Connecting to camera');
        await Camera.showPicker();
        console.log('Camera picked');
        await camera.connect();
        console.log('Connected to camera');
    }

    async function disconnect() {
        await camera.disconnect();
        console.log('Disconnected from camera');
    }
</script>

<button on:click={connect} on:keydown={connect}> Connect </button>
<button on:click={disconnect} on:keydown={disconnect}> Disconnect </button>

Steps to reproduce the issue:

Basic

  1. Click connect and pick the camera
  2. Click disconnect
  3. Click connect and pick the camera
  4. Crash

Full

  1. Click connect

  2. Console: Connecting to camera

  3. Select the camera from the device picker

  4. Console: Camera picked

  5. Console: Connected to camera

  6. Click disconnect

  7. Console: Disconnected from camera

  8. Click connect

  9. Console: Connecting to camera

  10. Select the camera from the device picker

  11. Console: Camera picked

  12. Console Error: Bindingerror

    Console Error: BindingError (Click for full log) { "name": "BindingError", "message": "Cannot use deleted val. handle = 0", "stack": "BindingError: Cannot use deleted val. handle = 0\n at Error. (http://localhost:5173/node_modules/web-gphoto2/build/libapi.mjs?v=a6df64ee:9:103581)\n at new (http://localhost:5173/node_modules/web-gphoto2/build/libapi.mjs?v=a6df64ee:9:103398)\n at throwBindingError (http://localhost:5173/node_modules/web-gphoto2/build/libapi.mjs?v=a6df64ee:9:104022)\n at Object.toValue (http://localhost:5173/node_modules/web-gphoto2/build/libapi.mjs?v=a6df64ee:9:132432)\n at __emval_get_property (http://localhost:5173/node_modules/web-gphoto2/build/libapi.mjs?v=a6df64ee:9:144427)\n at http://localhost:5173/node_modules/web-gphoto2/build/libapi.wasm:wasm-function[189]:0xb47e\n at http://localhost:5173/node_modules/web-gphoto2/build/libapi.wasm:wasm-function[1183]:0x8b5f8\n at http://localhost:5173/node_modules/web-gphoto2/build/libapi.wasm:wasm-function[402]:0x2b342\n at http://localhost:5173/node_modules/web-gphoto2/build/libapi.wasm:wasm-function[1223]:0x90fd8\n at http://localhost:5173/node_modules/web-gphoto2/build/libapi.wasm:wasm-function[2090]:0x11c09d" }
  13. Console Error: Memory access out of bounds

    Console Error: RuntimeError: memory access out of bounds (Click for full log) Uncaught (in promise) RuntimeError: memory access out of bounds at libapi.wasm:0xe8f9d at ret. (libapi.mjs?v=a6df64ee:9:125609) at Object.doRewind (libapi.mjs?v=a6df64ee:9:126898) at libapi.mjs?v=a6df64ee:9:127491
RReverser commented 1 year ago

Right, the API probably needs improvement then.

In the libapi.mjs I made the constructor async so it took care of connection too, but now the API suggests you can connect/disconnect same instance multiple times.

That's not the case as disconnect runs destructor and frees the C++ instance.

RReverser commented 10 months ago

I'm closing this one as it doesn't sound like there is much to be done here for now.

API improvements are always welcome.