So, I have a array with an custom structure which I want to sort according to an integer inside it.
However, when I run the sort function, it segfaults when accessing said integer to do the sorting and I do not understand what causes this.
Following is part of the code involved:
using GLib;
// A part of the structure
public struct Backend.TextModule {
public string text;
public uint text_start;
}
// A method inside the class utilizing this structure
class Post {
// The array in question
private TextModule?[] text_modules;
private void parse_text {
// Array is filled in a loop from reading in a JSON file
json.foreach_element ((array, index, element) => {
if (element.get_node_type () == OBJECT) {
Json.Object obj = element.get_object ();
Json.Array length = obj.get_array_member ("indices");
var entity = TextModule ();
entity.text = obj.get_string_member ("text");
entity.text_start = (uint) length.get_int_element (0);
text_modules += entity;
}
});
// The breaking sort function
qsort_with_data<TextModule?> (text_modules, text_modules.length, (a, b) => {
uint x, y;
x = a.text_start;
// FIXME: Somewhere here it segfaults...
y = b.text_start;
return (int) (x > y) - (int) (x < y);
});
}
}
I now have spend around a day trying to find the issue using the limited docs I could find, but to no result.
So, I do hope someone here can help me with my issue.