Maximum call stack size exceded - javascript

I am trying to download encrypted pictures and decrypt them using RNcryptor within a Javascript web application and place them within the html of my app. Everything works perfectly except for when pictures are larger in size and cause the call stack to be exceeded.
This error does not occur when to and from devices such as the Iphone, but when I try to send them to the web app, I get this error from the Iphone 6+ but no other device
This is my function used to convert a byte array to base64 string:
function encode(data)
{
var str = String.fromCharCode.apply(null,data);
return btoa(str).replace(/.{76}(?=.)/g,'$&\n');
}
Is there a more call stack efficient way to convert the data? I am willing to sacrifice speed if necessary.

The reason this is happening on only the Iphone 6 (and I assume it is mainly with pitcures made using its camera) is because the file you are sending is to large. This error probably would not occur with an older model Iphone such as the 5 or the 4 because of the picture quality.
The way that I would fix this is in your app where the picture is originally being encoded and placed on the database, I would resize it before doing so.

Related

Async fetch & decode of .wav file works on desktop, but not on mobile (WebAudioAPI)

I'm currently working on a web-based synthesizer program, using WebAudioAPI. It works quite well on desktop, but on mobile it seems to fail on loading & decoding the impulse response from a wav file.
The impulse response is used in conjunction with a convolver node, to implement a convolution reverb. Oddly enough, everything else works fine on mobile - oscillators, waveshapers, gain nodes, etc, and the application itself does not stop running (as it would if there were an unhandled exception). It's almost as if the file itself is not being decoded or loaded into the convolver node properly - when I send my sources to the node, on mobile, it outputs only silence.
Here is the code I have for performing these tasks:
//calculate reverb impulse response & assign to convolver node buffer
calcIR();
async function calcIR() {
let wavFile = await fetch("./wavData/ir4.wav");
let wavBuffer = await wavFile.arrayBuffer();
voice1.reverb.buffer = await synthCtx.decodeAudioData(wavBuffer);
}
in this case, buffer is the property of the convolver node which holds the decoded impulse response data, & synthCtx is my web audio context; ir4.wav is the actual impulse response. The async function call follows the synchronous instantiation of voice1, to make sure that the nodes are actually initialized before trying to change one of their properties.
I have not stopped playing around & troubleshooting, and I have a few more things I will probably try, but I figured I'd consult SE just to see if anyone here has an idea: ] also, just to clarify, I have indeed tested it on mobile, and I'm calling the resume() function on the context from a touchEnd event, so I know the issue isn't the context being muted. As above, everything works on mobile & sounds great - save for silence from the convolver node.
Any help is appreciated!
EDIT:
I've created a small jsfiddle demonstration to illustrate the problem I'm having.
The demo uses only a single square wave, routed into two gain nodes - one to the output (destination), and one to the convolver node (which is in turn routed to the destination). A slider controls the relative mix between the two.
fully left is fully dry (100% directly to output, 0% to convolver)
fully right is fully wet (0% directly to output, 100% to convolver)
Oddly enough, it seems I'm having the same problem in the fiddle, though it works perfectly well inside of my app. You can hear that the oscillator fades away into silence as the slider is moved, when it should be slowly fading in the reverberated signal.
I've tried to retain similarity between implementations, ie, I am calling the calcIR() function at the exact same place in my demo as I am within the actual app (just after finishing the connections, and just before starting the oscillators).
I also tried throwing some console.log()'s within the async function, just to see how far it is progressing - seems it's not even getting past the fetch stage. I've also confirmed the wav file availability is not the issue (hosted in a gcloud storage bucket, works elsewhere without any problems).
I admit I am still fairly new to async/await & working with promises in general, so I may just be misunderstanding something here. However, I'm not sure why one way would work in one place just fine and not at all in the other, though it certainly wouldn't be the first time.

Accessing Android List with Nativescript

The Short
I am trying to create a List<ScanFilter> in JavaScript by accessing Android API, as shown below:
var scanFilterList = new java.util.List<android.bluetooth.le.ScanFilter>;
However, JavaScript gives me a SyntaxError due to an unexpected token, which I presume is because of the angle brackets. Any assistance in overcoming this problem and creating a List<ScanFilter> would be greatly appreciated!!
The Long
I want to periodically run BluetoothLE scans in my NativeScript application (only worrying about the android side for the moment), even while the screen is turned off. To my understanding this would be possible, as stated in the documentation:
For unfiltered scans, scanning is stopped on screen off to save power. Scanning is resumed when screen is turned on again. To avoid this, do filtered scanning by using proper ScanFilter.
Source
I am attempting to create a ScanFilter to be used as a parameter for startScan() when it is called. However, when I try to create a new List as shown below:
var scanFilterList = new java.util.List<android.bluetooth.le.ScanFilter>;
I get a SyntaxError due to an unexpected token. I am assuming this is because the angle-brackets aren't recognized by JavaScript and cause problems.
How can I bypass this problem and successfully create a List<ScanFilter> variable in JavaScript for use.

iPhone crash for feeding base64 to webview

I am using UIImagePickerController to choose image/video,upon selection I am converting the resource into base64 string and I am sending that to wkwebview
NSData(contentsOfURL:(info[UIImagePickerControllerMediaURL] as? NSURL)!)?.base64EncodedDataWithOptions(NSDataBase64EncodingOptions.Encoding64CharacterLineLength)
I am sending the base64 string to webview using evaluatejavascript
Here is the JS function
function showResource(base64,type){
if (type == "image"){
document.getElementById("div1").innerHTML="<img src='data:image/jpeg;base64,"+base64+"' width='100' height='100' alt='No Image'/>";
}
else{
document.getElementById("div1").innerHTML="<video width='320' height='240' controls><source src='data:video/x-m4v;base64,"+base64+"'></video>";
}
}.
I am facing the following problems
sometimes the webpage that is in webview becomes blank
sometimes the application gets crashed
sometimes the device goes into multiple
reboot
I couldn't find any memory leak in native code.I tried Instruments.
try loading a video of 25 seconds long first time it won't crash and you can't find a memory leak in Instruments
try loading the same video again the results are same
try doing the same,this time you'll see the device has gone offline
or if we try to load a video that's 60 longs it will crash the first time itself.
I am not sure what's causing the problem.
As the page is turning blank , it could be a javascript memory leak I thought
But I don't think the above function can cause memory leak since we're reassigning the new base64 on the same variable the older base64 should have been released from the memory and moreover javascript is garbage collected language.
so this is contradicting.
so base64 conversion might take more memory which in turn causes iOS to crash the app or crash the iPhone also in worst case but if this is the case why sometime html page is turning blank.
so this is also contradicting.
Any help is appreciated !
Update:
So far in my research it shows the problem is with memory leak in javascript.
If xcode print "pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug" ,try to turn off the safari web viewer.

GetJSObject fails when run on Microsoft Surface (Excel-VBA)

I have written a small utility in Excel-VBA that also interacts with Acrobat Javascript in a handful of separate .pdf files.
The code has been tested extensively and runs exactly as intended on my desktop PC. However, I ultimately need to implement this code on a Microsoft Surface platform. When I try to run the same code from an Excel file on a Microsoft Surface, the code balks at any lines utilizing "GetJSObject."
Eg. The following works fine on my PC, but causes an "object or method not supported" error on my Surface.
Set gAPP = CreateObject("AcroExch.App")
Set gPDDOC = CreateObject("AcroExch.PDDoc")
If gPDDoc.Open(pdfFileName) Then Set jso = gPDDOC.GetJSObject
So far, I've been able to find some hints online that GetJSObject doesnt work well in a 64 bit environment and my Surface runs 64 bit Windows 10 and 32 bit Excel.
However, I don't think that this alone can account for the difference in behavior across both machines; my desktop is running 64-bit Windows 7 with 32 bit Excel, and everything works as intended.
Where should I be looking to help discover the source (and solution) of the problem?
EDIT/UPDATE: The getJSObject statement actually works as intended, IF I take the additional step of manually opening a copy of one of the relevant .pdf files in Acrobat prior to running my VBA code. I assume this means that it is somehow the object definitions (e.g. Set gAPP = CreateObject("AcroExch.App")) that are working differently on the Surface relative to my PC--and not the getJSObject command specifically, as originally thought?
So far, it hasnt made much sense to me how/why this could be true (let alone how I could go about resolving the issue).
Not sure if this had been answered yet, however there are two courses of action i'd take for research:
1.
See if you can launch it without the constructor by using:
Set AcroApp = New AcroApp
Rather than
Set AcroApp = CreateObject("AcroExch.App")
2.
Ensure you are using the same version of acrobat, from my research this error occurs from the very first result in Google for the search query:
createobject acroexch.app error 429
You cannot do this with Adobe Reader, you need Adobe Acrobat.
This OLE interface is available with Adobe Acrobat, not Adobe Reader.

HTML 5 File API gives length of 0 when selecting 2000 files

I have the following:
HTML
<input id="files" name="files" type="file" multiple="multiple" />
<button id='subButton' type='submit'>Upload (0) files</button>
Javascript
$("#files").change(function(evt) {
debugger;
$("#subButton").text("Upload (" + evt.target.files.length + ") files");
});
You can see it in action in this Fiddle. If I select 1,700 files, the code works fine and the correct number of files is returned by evt.target.files.length. However, if I select all the files in my directory (2279 -- total size of 210MB), then evt.target.files.length returns a 0.
Is there some sort of ambiguous file limit with the File API?
In my web.config I have: maxRequestLength="700000" which should handle the given size of the files. However, this seems to be a client rather than a server side issue to me in that nothing is being submitted to the server.
Any ideas?
This is not a limit of the HTML5 File API but of the browser implementation or operating system.
Testing Firefox on Windows Vista, for example, there seemed to be effectively no limit to the number of files I could select (I tested up to 10,000). On Chrome, it appeared to return 3758 of the selected files.
The difference is that Firefox is using the new IFileOpenDialog interface which returns the selected files as an enumeration, but Chrome seems to be using the old GetOpenFileName API, which relies on a fixed size buffer. If the buffer isn't big enough, it's supposed to return an error, but on Vista it just returns truncated and slightly corrupted data.
Interestingly, from the number of files returned by Chrome, and the knowledge of the filenames I was testing with, I can make a fairly good guess that the buffer size being used is probably 32768.
I'm guessing you're using Windows 7 or 8 and the GetOpenFileName API has been fixed to the extent that it now returns an error if you exceed the buffer size. So when you select too many files, the browser doesn't attempt to process the truncated data, and just returns 0.
The exact limit will be based on the length of the filenames and the path of the directory containing those files.
Other operating systems will obviously not have these same limits, but could have their own problems depending on the design of their file selection APIs.

Categories