2178: Exception when calling getArrayBuffer()

Help improve MediaMonkey 5 by testing the latest pre-release builds, and reporting bugs and feature requests.

Moderator: Gurus

TIV73
Posts: 229
Joined: Sat Nov 12, 2011 1:31 pm

2178: Exception when calling getArrayBuffer()

Post by TIV73 »

Hi there,
I discovered some weird behavior when calling getArrayBuffer() on a file buffer. To reproduce run the following function:

Code: Select all

async function FileTest(){
  var fileName = '[somefilename]'

  var exportObj = {
    "property1": "value1",
    "property2": "value2"
  }

  await app.filesystem.saveTextToFileAsync(fileName, JSON.stringify(exportObj), 'UTF-8');

  var file = await app.filesystem.getFileContentAsync(fileName);

  // Works only once
  var fileBuffer = file.getArrayBuffer();
  
  var fileSlice = fileBuffer.slice(0);
  var importText = new TextDecoder('utf-8').decode(fileSlice);
  console.log(JSON.parse(importText));
}
Everything works fine the once, but when the function is called a second time, file.getArrayBuffer() throws a MediaMonkeyEngine Access violation exception. I uploaded a couple of bug reports with ID 85E5C86D at around 20:01 on 2019-05-25.
PetrCBR
Posts: 1763
Joined: Tue Mar 07, 2006 5:31 pm
Location: Czech
Contact:

Re: 2178: Exception when calling getArrayBuffer()

Post by PetrCBR »

From the log it looks like chromium already release file object. What's the reason you request array buffer twice ?
How to make a debuglog - step 4b: viewtopic.php?f=30&t=86643
TIV73
Posts: 229
Joined: Sat Nov 12, 2011 1:31 pm

Re: 2178: Exception when calling getArrayBuffer()

Post by TIV73 »

Isn't opening files for whatever reason kind of a common use case? It's not too far fetched to assume that after a file is read, it's modified by an external process and therefore needs to be loaded a second time.

Besides, I'm not talking about reading the same file buffer twice in a row. What I mean is that, after the buffer of a file was read once, an exception occurs everytime the buffer of any file is requested, regardless of timing. Loading File A, waiting a couple of minutes and then loading File B would also trigger it.

To rephrase it, at the moment it's impossible to load more than a single file during a session using the method above. Well, either that or I'm doing it wrong.
TIV73
Posts: 229
Joined: Sat Nov 12, 2011 1:31 pm

Re: 2178: Exception when calling getArrayBuffer()

Post by TIV73 »

Small update: I wanted to make sure that it's not just a handling issue related to async/await and tried it with promises:

Code: Select all

function WriteFile(fileName){
  var exportObj = {
    "property1": "value1",
    "property2": "value2"
  }

  app.filesystem.saveTextToFileAsync(fileName, JSON.stringify(exportObj), 'UTF-8');
}

function FileTest(fileName) {
  app.filesystem.getFileContentAsync(fileName).then(function(file) {
    var fileBuffer = file.getArrayBuffer();
    var fileSlice = fileBuffer.slice(0);
    var importText = new TextDecoder('utf-8').decode(fileSlice);
    console.log(JSON.parse(importText));
  })
}

var firstFile = '[someFilePath]'
var secondFile = '[someOtherFilePath]'
WriteFile(firstFile) // ok
WriteFile(secondFile) // ok
FileTest(firstFile) // ok
FileTest(secondFile) // exception
The result remained the same.
PetrCBR
Posts: 1763
Joined: Tue Mar 07, 2006 5:31 pm
Location: Czech
Contact:

Re: 2178: Exception when calling getArrayBuffer()

Post by PetrCBR »

Probably it has something with garbage collection we're force before getArrayBuffer call.
How to make a debuglog - step 4b: viewtopic.php?f=30&t=86643
Post Reply