简体   繁体   English

@@@正在中止:dlfree addr中的无效堆地址= 0x00000156

[英]@@@ ABORTING: INVALID HEAP ADDRESS IN dlfree addr=0x00000156

I have begun to try and keep some data persistant in my views when my device is rotated. 旋转设备后,我开始尝试在视图中保留一些数据。 Since implementing this after awhile my app will crash with the error: 由于一段时间后实现了此操作,我的应用程序将因错误而崩溃:

@@@ ABORTING: INVALID HEAP ADDRESS IN dlfree addr=0x00000156
Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 20787 (FinalizerDaemon)

After the app crashed every time I try to reopen it i get this same error instantly until I uninstall the app. 每次我尝试重新打开该应用程序后,其崩溃都会立即出现相同的错误,直到我卸载该应用程序为止。

Does anyone know what causes this error? 有人知道导致此错误的原因吗?

Here is the code I used to save my data: 这是我用来保存数据的代码:

onDestory() : onDestory()

    System.out.println("Saving");
    ArrayList<Path> strokes = paintCanvas.strokes;
    ArrayList<Integer> colors = paintCanvas.colors;
    SharedPreferences settings = getSharedPreferences("colors", MODE_PRIVATE);
    settings.unregisterOnSharedPreferenceChangeListener(listener);



    /**Write Colors**/
    try
    {
        FileOutputStream os = openFileOutput("drawing.dat", MODE_PRIVATE);
        ObjectOutputStream output = new ObjectOutputStream(os);
        output.writeObject(colors);
        output.close();
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }

    /**Write Paths**/
    try
    {

        Gson gson = new Gson();

        File file = getFileStreamPath("paths.txt");
        FileWriter writer = new FileWriter(file);
        BufferedWriter output = new BufferedWriter(writer);
        for(Path p : strokes)
        {
            String s = gson.toJson(p);
            s = s + "\n";
            output.write(s);
        }

        output.close();
    }
    catch (Exception e)
    {
        e.printStackTrace();
        //System.out.println(e.getMessage());
    }

In onCreate() : onCreate()

    //Try Load here!
    /**Read Colors**/
    try
    {
        ArrayList<Integer> colors;
        ArrayList<Path> strokes;
        FileInputStream ins = openFileInput("drawing.dat");
        ObjectInputStream reader = new ObjectInputStream(ins);
        colors = (ArrayList<Integer>)reader.readObject();

        paintCanvas.colors = colors;
        System.out.println("Colors Loaded");
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }

    /**Read Paths**/
    try
    {
        FileInputStream fis = openFileInput("paths.txt");
        InputStreamReader isr = new InputStreamReader(fis);
        BufferedReader bufferedReader = new BufferedReader(isr);
        StringBuilder sb = new StringBuilder();
        String line;
        Gson gson = new Gson();

        ArrayList<Path> paths = new ArrayList<Path>();
        while ((line = bufferedReader.readLine()) != null)
        {   
            paths.add(gson.fromJson(line,Path.class));
        }


        paintCanvas.strokes = paths;
        paintCanvas.currentStroke = paintCanvas.strokes.size() - 1;
        System.out.println("Paths Loaded");
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }

Path Objects are not serializable. Path对象不可序列化。 I believe this was causing the error, to get around this I created a custom data structure that implements serializable to hold the instructions of each path and then constructed my paths off of that. 我相信这是导致错误的原因,为了解决这个问题,我创建了一个自定义数据结构,该结构实现可序列化以保存每个路径的指令,然后从该路径构造我的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM