Gerrit Niezen

Maker of open-source software and hardware.

After finally getting the LZO decompression module working on 32-bit Windows, there was one more issue that popped up resulting in a malloc: Incorrect checksum for freed object error.

First I thought there was something wrong with my macOS version of the avutil shared library, as the error was occurring on macOS but not in Linux. After some debugging I discovered that it didn't occur every single time the code was run, indicating that it's some kind of buffer overflow that was occurring instead.

When increasing the size of the output buffer by one, ie., malloc(outputBufferSize + 1), the error stopped happening. Then my colleague Lennart discovered that the LZO code in libavutil requires the buffers to be padded by a certain number of bytes. I added the AV_LZO_INPUT_PADDING and AV_LZO_OUTPUT_PADDING constants in the header file to the buffer sizes, and so far everything finally seems to work without any problems.

#Node.js

Last week I discovered write.as/WriteFreely which seems like a great alternative to Ghost. I started using Ghost because I really liked their Markdown editor and the ability to write posts on mobile. Unfortunately, with the new release of Ghost they have changed their editor to look more like Medium, and it's a bit buggy on mobile. Now while I really like Ghost, their target market is teams. I'm currently using a paid theme that seems more suited to a single author blog, but it's not ideal.

Write.as has an iOS mobile app and even a Linux desktop app. It looks great, is also open source and even federates with Mastodon! I guess the main thing will be to see if I can port the more than 100 blog posts I currently have on here over.

Once a month there's a street market just down the road from us, selling everything from jewellery to baklava. It's something we enjoy doing on a Saturday morning, just strolling through the stalls and maybe have a coffee at a nearby cafe.

This morning I noticed a South African flag waving through the window of the coffee shop where we were sitting. That could only mean one thing: The stall selling boerewors rolls and South African treats were there! Boerewors is a type of sausage made with mince and a special blend of spices. I bought a whole spiral of venison boerewors with jalapeno's. Not very traditional, but I'm looking forward to tasting it.

I also bought a pack of buttermilk rusks. South African rusks are similar to biscotti, in that it's also a type of double-baked biscuit/bread that you can dunk in coffee. I've made my own rusks a couple of times already, but they have to bake overnight so when I'm lazy buying them is a bit easier.

I have a Next Thing Co. CHIP single board computer (unfortunately discontinued) that I use to run homebridge, in order to connect HomeKit to my Hive home setup. So that I can control my thermostat and lights using Siri on my phone you see!

What is a little bit annoying is that the flashing lights on the CHIP makes my study look like a disco at night. I want a little case that covers the lights – Thingiverse to the rescue! There are quite a few designs for CHIP cases, so I decided to settle on the one that has been made the most.

It's currently printing on my Prusa i3 MK3 and should take around 30 minutes. Just before printing the printer let me know that there's a new firmware version available, probably because I upgraded the slicer software. Having a really long USB type B cable makes updating the firmware super easy, as I can connect the computer to the printer without having to move things around.

#Making

Oops, I skipped a day yesterday. Mainly it was because I was visiting Cellnovo at the Sony UK Technology Centre in Pencoed, and I only got back late in the afternoon. Sony Pencoed is where the Raspberry Pi is made, but I wasn't there for the Pi. I was there to learn more about Cellnovo's insulin pump.

I'll post more details in the future, but let's just say for now that it was pretty impressive to see what goes into making a high-accuracy insulin delivery device. Cellnovo started out here in Swansea in 2002, and moved to Pencoed just outside of Bridgend in 2016. It's great to know that there's a state-of-the-art insulin pump being manufactured less than an hour's drive from where I live.

Feature image

I struggled for two days straight to get my LZO Node module working on Windows. It kept on complaining about “A dynamic link library (DLL) initialization routine failed.” when trying to use it in Electron on Windows. It turns out that this is due to a bug in Electron and Node. The funny thing is that there is a workaround implemented in the prebuildify dependency I'm using, but I was just not using the latest version. Always check your dependency versions kids!

There was one more twist: It still wouldn't work on 32-bit Windows, resulting in a “Module not found” error when it's clearly in the right directory. It seems to have something to do with the avutil-56.dll I built, as using a prebuilt .dll works fine. I do need to build my own, as prebuilt ones are usually not LGPL licensed. So now I'm rebuilding FFmpeg for the umpteenth time, this time round using the ffmpeg-windows-build-helpers script to build LGPL-licensed 32-bit and 64-bit cross-compiled shared libraries:

./cross_compile_ffmpeg.sh --enable-gpl=n --build-ffmpeg-shared=y --compiler-flavors=multi

#Node.js

Feature image

I don't think I have ever had pumpkin pie before. To my understanding it is mainly eaten during Thanksgiving in the US. When we recently went to pick some pumpkins on a nearby farm for Halloween decorations, we made sure to get enough to make some soup and pie as well.

Today I cleaned and cubed one of the remain pumpkins we had, and attempted baking a pumpkin pie for the first time. I bought the shortcrust pastry, so that I just had to roll it out, but the rest was made from scratch. It's a nice feeling knowing that the pumpkin you picked from a field yourself is going into a pie you're baking yourself.

The pie came out of the oven looking reasonably edible, if not as pretty as the picture in the recipe I used. It's now in the fridge chilling for a while, and I'm looking forward to having a slice with a cup of coffee in a minute.

Feature image

I enjoy using GNOME Boxes for virtual machines so much! I've already written about how horrible the experience of trying to use Virtualbox or VMWare on Linux is, and that everything just works in Boxes.

Having used it for a couple of months now, it is still working without any issues and has some delightful features:

  • There is a “Send file..” option, where you can send a file to the guest VM without even having to install any plugins.
  • The “Share Clipboard” option means you can copy & paste between the host and the guest VM.
  • If you do install the SPICE plugins on the guest VM, you can start sharing folders without even having to reboot the VM

And while writing this post I just discovered that I can connect remotely over VNC to my Windows test laptops using Boxes as well!

Feature image

I found the reason why I didn't get av_lzo1x_decode compiled into the avutil library when cross-compiling to Windows from Linux the first time (as described in yesterday's blog post). Basically I needed to do sudo apt-get install mingw-w64-tools first, which adds a tool that ensures the necessary library functions get compiled in. Who knew?

Because the flag to use run-time references is enabled by default, you need to recreate the import library from the .dll file using the .def file:

lib /machine:x64 /def:avutil-56.def /out:avutil.lib

Note that if you're using a avutil-56.def file, your executable will be looking for a avutil-56.dll, not avutil.dll as expected. I had to use Dependency Walker to figure this out. And then I discovered that I only built the 32-bit DLL. To build for 64-bit, use:

./configure --enable-shared --arch=x86_64 --target-os=mingw32 --cross-prefix=x86_64-w64-mingw32-

By the way, if you want to check if a DLL file is 32-bit or 64-bit, you can use

dumpbin /headers avutil-56.dll | findstr machine

To use the right DLL with the right architecture, I used the following snippet based on headless-gl's binding.gyp:

'copies': [
  {
    'destination': '$(SolutionDir)$(ConfigurationName)',
    'files': [
      '<(module_root_dir)/lib/<(target_arch)/avutil-56.dll'
    ]
  }
]

This will copy the DLL from either lib/x64 or lib/x86 and put it in the same folder as module.node. Nice!

#Node.js

Feature image

I've been away at a Tidepool offsite, which explains the lack of updates to the blog. Hopefully we'll be back to regularly daily updates from now onward.

I've been struggling to successfully link to the avutil shared library on Windows. I thought it was because of a problem with the settings in my binding.gyp file, but it turns out I somehow didn't build the required routine into the DLL file. I just discovered that there's a command on Windows that you can use to inspect DLL files.

dumpbin /exports avutil.dll

This lists all the symbol entries. I expected av_lzo1x_decode to be in there, and surprisingly it wasn't. Note that to use this command you need to have Visual Studio installed and then open a Developer Command Prompt or add it to your path.

Enter your email to subscribe to updates.