Page 1 of 1

Gambas' object serialization, segmentation fault (11) [Solved]

Posted: Monday 1st March 2021 6:45am
by Godzilla
Hello,

I'm basing my project (included in this post) on the code example at this link:

https://gambaswiki.org/wiki/lang/special/read

This code is a crude but a fully-working example of the built-in object serialization, introduced in the stable release of Gambas 3.15.0. It doesn't crash or cause a segmentation fault. It works completely as expected.

So what I'm doing that's causing the segmentation fault: I've come across a unique situation where the best method of handling a particular data-set I'm working with, is to have a class array, wherein one of its elements is, in itself, a separate second class array.

It works flawlessly within the program, to my surprise, aside from being complicated. The problem comes from my attempt at serializing such a bizarre class array for "_write" and "_read".

Serializing "_write" works, in that a non-zero size data file gets written, and doesn't cause a segmentation fault. However, I don't know if all the elements in the class array are being written completely. The only way to know, is by doing a serializing "_read" of the data file. And that's where the segmentation fault happens. Specifically, at the point where the sub-element class array is attempting to be read.

The segmentation fault is most likely my own doing, because I'm simply guessing at how to properly do the "_write" and "_read" in this particular unique situation. If someone can fix this code and make it work, it would be immensely helpful, if its at all possible.

On the other hand, if its a bug in Gambas, I understand that there's no way BenoƮt could have possibly foreseen someone trying to do something as bizarre as what I'm attempting to do.

The project I'm attaching is an over-simplified example of a class array, containing one element that is in itself an whole other separate class array. It works by:

Click the Step 1 button, which puts values in all the class array elements.
Click the Step 2 button, which writes the class array to a file "item.bin" in the application path
Click the Step 3 button, which attempts to read from "item.bin" into the class array, and causing the segmentation fault

My system:
Gambas 3.15.2, Kernel: 5.4.0-66-generic x86_64 bits: 64 compiler: gcc v: 9.3.0 Desktop: MATE 1.24.0 wm: marco dm: LightDM Distro: Linux Mint 20 Ulyana base: Ubuntu 20.04 focal

Thanks for reading, and thanks for any help.

Edit: the attached project in this message doesn't work. The project attached to the 2nd message in this thread is a 100% working solution to the problem.

Re: Gambas' object serialization, segmentation fault (11)

Posted: Tuesday 2nd March 2021 8:06am
by Godzilla
I happy to report back that I managed to get the "_write" and "_read" object serialization of my bizarre Frankenstein class array working. That was complicated!

I don't know if my working project attached to this message will ever help anyone else (if it does, I'm delighted). But for me, this is a total game-changer.

Never give up. I've discovered that when I'm ready to throw my mouse across the room in frustration, is when the next idea for a possible solution pops into my head.

And yes, I still use my VB6 style of coding. I guess I'm old and set in my ways. :D