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

Cannot reconnect after disconnecting #8

Closed
icheered opened this issue Aug 6, 2023 · 2 comments
Closed

Cannot reconnect after disconnecting #8

icheered opened this issue Aug 6, 2023 · 2 comments

Comments

@icheered
Copy link
Contributor

icheered commented Aug 6, 2023

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" }
  1. 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
Copy link
Collaborator

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
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants