Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

243
Views
Electron app crashes when storing data to system (app exited with code 3221225477)

I am working on an electron app, and I'm using an the following class implementation to save and retrieve data from the user's disk. Sometimes this functions correctly, however, on occasion the program will crash and output this error.

app exited with code 3221225477

I am not too sure what is causing this issue. I understand this error code means there is an access violation occurring, but I'm not sure why that is. Potentially could be the implementation of the class. I simply took the implementation from here https://medium.com/cameron-nokes/how-to-store-user-data-in-electron-3ba6bf66bc1e

There are also occasions when this occurs randomly too, so it may not be the Store implementation.

const electron = require('electron');
const path = require('path');
const fs = require('fs');


class Store {
  constructor(opts) {
    // Renderer process has to get `app` module via `remote`, whereas the main process can get it directly
    // app.getPath('userData') will return a string of the user's app data directory path.
    const userDataPath = (electron.app || electron.remote.app).getPath('userData');
    // We'll use the `configName` property to set the file name and path.join to bring it all together as a string
    this.path = path.join(userDataPath, opts.configName + '.json');
    
    this.data = parseDataFile(this.path, opts.defaults);
  }
  
  // This will just return the property on the `data` object
  get(key) {
    const val = this.data[key];
    console.log('Get', key, val);
    return val;
  }
  
  // ...and this will set it
  set(key, val) {
    console.log('Set', key, val)
    this.data[key] = val;
    // Wait, I thought using the node.js' synchronous APIs was bad form?
    // We're not writing a server so there's not nearly the same IO demand on the process
    // Also if we used an async API and our app was quit before the asynchronous write had a chance to complete,
    // we might lose that data. Note that in a real app, we would try/catch this.
    fs.writeFileSync(this.path, JSON.stringify(this.data));
  }
}

function parseDataFile(filePath, defaults) {
  // We'll try/catch it in case the file doesn't exist yet, which will be the case on the first application run.
  // `fs.readFileSync` will return a JSON string which we then parse into a Javascript object
  try {
    return JSON.parse(fs.readFileSync(filePath));
  } catch(error) {
    // if there was some kind of error, return the passed in defaults instead.
    return defaults;
  }
}

// expose the class
module.exports = Store;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I seem to have discovered the reason for this issue. The following post contains a comment which says

Keep a global reference of the window object, if you don't, the window will be closed automatically when the JavaScript object is garbage collected.

https://stackoverflow.com/a/59796326/7259551

Simply making the instance of BrowserWindow a global value fixed this issue.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!