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

Large MIDI files cause RangeError: Maximum call stack size exceeded when writing to bytes #35

Open
ghost opened this issue Dec 25, 2017 · 0 comments

Comments

@ghost
Copy link

ghost commented Dec 25, 2017

When writing a large midi file using File.prototype.toBytes(), an error is thrown::

/Users/me/node_modules/jsmidgen/lib/jsmidgen.js:122
			return String.fromCharCode.apply(null, byteArray);
			                           ^

RangeError: Maximum call stack size exceeded
    at Object.codes2Str (/Users/me/node_modules/jsmidgen/lib/jsmidgen.js:122:31)
    at /Users/me/node_modules/jsmidgen/lib/jsmidgen.js:658:18
    at Array.forEach (<anonymous>)
    at File.toBytes (/Users/me/node_modules/jsmidgen/lib/jsmidgen.js:657:15)
    at end (/Users/me/Desktop/mpp2midi/main.js:72:48)
    at ReadStream.<anonymous> (/Users/me/Desktop/mpp2midi/main.js:123:34)
    at emitOne (events.js:116:13)
    at ReadStream.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)

I personally solved it by replacing the following code

jsmidgen/lib/jsmidgen.js

Lines 121 to 123 in 97c1270

codes2Str: function(byteArray) {
return String.fromCharCode.apply(null, byteArray);
},

with this

		codes2Str: function(byteArray) {
			var string = "";
			byteArray.forEach(byte => string += String.fromCharCode(byte));
			return string;
		},
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

0 participants