简体   繁体   English

Mono c#TextView缓冲区反序列化导致崩溃

[英]Mono c# TextView Buffer Deserialize Keeps Crashing

I can not figure out why this keeps crashing! 我不知道为什么这总是崩溃! I have this inserted into a method that presents the FileChooser allows the user to choose a file and then if file was chosen run this piece of code. 我已将此插入到一种方法中,该方法提供FileChooser允许用户选择文件,然后如果选择了文件,请运行此代码。 I have commented out the lines run the program and systematically and tracked it down to the buffer.Deserialize line. 我已经注释掉了运行程序的行并系统地对其进行了跟踪,并将其跟踪到buffer.Deserialize行。 It will run and not crash until this line is added. 在添加此行之前,它将运行并且不会崩溃。 Of coarse the TextView Buffer Text does not every get updated. 粗糙的TextView Buffer Text并非每次都会更新。

Also Before you comment the file that is opened is a valid saved file and the method to serialize and save file works flawlessly. 同样,在注释打开的文件之前,该文件是有效的保存文件,并且序列化和保存文件的方法可以正常工作。 It is just the problem with opening that crashes. 崩溃只是问题所在。

byte[] data = System.IO.File.ReadAllBytes(fileChooser.Filename);

TextBuffer buffer = new TextView().Buffer;
Gdk.Atom serialFormat = buffer.RegisterDeserializeTagset(null); 
ulong length = (ulong) data.LongLength; 
TextIter iterator = buffer.StartIter; 
buffer.Deserialize ( buffer, serialFormat, ref iterator, data, length );

For those of you who want to be wise guys and say it is the saved file here is the saved file I am trying to open that crashes it. 对于那些想要成为聪明人并说这是保存的文件的人,这里是我尝试打开的保存文件,导致崩溃。 Well any file crashes it but this is my test file. 好吧,任何文件都将其崩溃,但这是我的测试文件。

GTKTEXTBUFFERCONTENTS-0001   Î <text_view_markup>
 <tags>
  <tag id="0" priority="0">
   <attr name="weight" type="gint" value="700" />
  </tag>
 </tags>
<text><apply_tag id="0">
Bold
</apply_tag>Hello World!</text>
</text_view_markup>

Update: I made some more modifications to try and get some debug information out of the program as the way it was running it was just crashing and giving nothing of value when it crashed. 更新:我进行了一些修改,以尝试从程序中获取一些调试信息,因为它的运行方式只是崩溃而崩溃时没有任何价值。 I now get this from the Debugger. 我现在从调试器中获得此信息。

GLib.GException: Line 8 character 1: Anonymous tag found and tags can not be created. at Gtk.TextBuffer.Deserialize(TextBuffer content_buffer, Atom format, TextIter& iter, Byte[] data, UInt64 length)

I was able to stop the crashing but now have other issues with trying to get it to run correctly. 我能够停止崩溃,但是现在尝试使其正常运行时还有其他问题。 The original question is no longer the problem. 原来的问题不再是问题。

Solved the original by changing 通过更改解决原件

to this code 这个代码

private string mimeType = "text/plain";
...
buffer.Deserialize ( 
                    mainEditor.Buffer, 
                    mainEditor.Buffer.RegisterDeserializeTagset(mimeType), 
                    ref iterator, 
                    data, 
                    (ulong)data.LongLength
                );

It needed a proper mimeType otherwise it crashed, even though the documentation says it would except null as a valid option! 它需要一个合适的mimeType,否则它会崩溃,即使文档说它会除null之外还是一个有效选项!

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

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