Skip to content

Fix useBuffer() targetView assignment #168

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

iamarkdev
Copy link

The useBuffer() method was not properly initializing the module-level targetView variable, causing TypeError: undefined is not an object (evaluating 'targetView.setFloat64') and similar errors when packing data that requires DataView operations.

Root Cause

When useBuffer(buffer) is called, it correctly sets:

  • ✅ target = buffer
  • ✅ position = 0
  • ❌ targetView remains undefined
    Later, when pack() executes, it checks if (!target) to decide whether to initialize. Since target is already set by useBuffer(), the initialization block that sets targetView = target.dataView is skipped, leaving targetView undefined.

Fix

Added targetView = target.dataView to useBuffer() to ensure both target and targetView are properly initialized when using external buffers.

This enables proper buffer reuse patterns and prevents runtime errors when packing numbers, which require DataView methods like setFloat64(), setUint32(), etc.

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

Successfully merging this pull request may close these issues.

1 participant