Aunty Langton's Musical Ant needs YOUR help!

Hi guys,

image

This is a long time coming… As you can see from the git commits below, I’ve been struggling with one or more bugs for quite some time. The crashes I’m seeing all seem to point towards an invalid memory reference. The object seems to be an int based on the errors I’m seeing. The crash is much more likely when I’m running multiple instances. I suspect this may be due to shared pointers between module instances but again, I’m not 100% sure.

Background/Context Developed on MacOS, Tested mostly on MacOS (and some Win10)

This plugin is essentially an X, Y voltage output of ant coordinates for the Langton’s Ant system. It has other bells + whistles: quantisation (borrowed from JW modules - thanks!), a second “shadow” ant which has fun interactions with the first ant. There is also a step skipping and looping functionality (stateless).

Initial development: Life, ants and Brain. Just tossing an idea! - #20 by Owleyeyeye

Example of some ants in action: https://www.youtube.com/watch?v=b8--aKFVYvk

Some early investigation into the bug: Segfault crash associated with Chronoblob2 - #14 by Owleyeyeye

Evidence of frustration and banging-head-against-wall:

Crash Example

Process:               Rack [2739]
Path:                  /Applications/Rack.app/Contents/MacOS/./Rack
Identifier:            com.vcvrack.rack
Version:               1.1.6 (1.1.6)
Code Type:             X86-64 (Native)
Parent Process:        bash [2705]
Responsible:           Terminal [2703]
User ID:               501

Date/Time:             2019-12-14 09:51:48.951 +1100
OS Version:            Mac OS X 10.15.1 (19B88)
Report Version:        12
Anonymous UUID:        C4657299-4478-42F3-57EF-465A7F04BE59

Sleep/Wake UUID:       5C002B35-5B5C-49E4-987F-A6F480B44226

Time Awake Since Boot: 9800 seconds
Time Since Wake:       5600 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Application Specific Information:
abort() called
Rack(2739,0x1049f9dc0) malloc: *** error for object 0x1: pointer being freed was not allocated
 

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib        	0x00007fff6c8b449a __pthread_kill + 10
1   libsystem_pthread.dylib       	0x00007fff6c9716cb pthread_kill + 384
2   libsystem_c.dylib             	0x00007fff6c83ca1c abort + 120
3   com.vcvrack.rack              	0x000000010427559e fatalSignalHandler(int) + 510
4   libsystem_platform.dylib      	0x00007fff6c966b1d _sigtramp + 29
5   dyld                          	0x00000001049467fb ImageLoader::trieWalk(unsigned char const*, unsigned char const*, char const*) + 183
6   libsystem_c.dylib             	0x00007fff6c83ca1c abort + 120
7   libsystem_malloc.dylib        	0x00007fff6c92cd20 malloc_vreport + 548
8   libsystem_malloc.dylib        	0x00007fff6c92cade malloc_report + 151
9   com.vcvrack.rack              	0x000000010435b288 json_delete + 136
10  com.vcvrack.rack              	0x000000010435b26f json_delete + 111
11  com.vcvrack.rack              	0x00000001043532f4 hashtable_close + 84
12  com.vcvrack.rack              	0x000000010435b230 json_delete + 48
13  com.vcvrack.rack              	0x00000001043532f4 hashtable_close + 84
14  com.vcvrack.rack              	0x000000010435b230 json_delete + 48
15  com.vcvrack.rack              	0x000000010435b26f json_delete + 111
16  com.vcvrack.rack              	0x00000001043532f4 hashtable_close + 84
17  com.vcvrack.rack              	0x000000010435b230 json_delete + 48
18  com.vcvrack.rack              	0x000000010427937f rack::PatchManager::save(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) + 367
19  com.vcvrack.rack              	0x00000001042abfa9 rack::app::Scene::step() + 201
20  com.vcvrack.rack              	0x000000010428d24a rack::Window::run() + 1226
21  com.vcvrack.rack              	0x0000000104274efa main + 1434
22  com.vcvrack.rack              	0x000000010420e034 start + 52

Help?

I’ve just made the github repo public in the hope that someone may be able to help. I would really love to be able to release this thing as a stable module.

I should be clear in saying that this is my first VCV Rack plugin and I’m not a professional dev. There could well be multiple things going wrong here. Spaghetti-code dragons most likely. So, apologies in advance for that.

Git repo: https://github.com/64MM4-KN1F3/AuntyLangtons/tree/NewPath

If anyone might like to help and would like a code walk through, I’d be happy to jump on a screenshare/call to do so. :slight_smile:

Cheers all, Owleyeyeye

I didn’t run it (is there a patch so we can try it?) but from skimming the code quickly I’m pretty dubious that at this line

You really want std::numeric_limits::max() which is “the largest int there is” or (on your mac) 2^31 or so. What are you trying to accomplish with that comparison? Seems index will increase without bound basically (although i didn’t trace every use of it it does seem that it is mostly modded)

why all of the dynamic casts all over the place? that’s a big red flag for me - I’d look at your widget code if I were you.

Great, thanks for the input @baconpaul.

To be honest, this index value was needed in previous versions when looping functionality was not stateless but I reckon I can probably get rid of it now. Will have a crack at that shortly.

Hi @jerrysv, Okay, another area for me to focus on. I’ll get rid of them and use conversion methods if absolutely necessary.

As to the “why?”. I learned C at uni and that must have been what I was taught for that. Outdated syntax for C++ I see…

Cheers.

given that you’re on a Mac, you can compile with -g and run it with a debugger (lldb ./Rack)

configParam(MusicalAnt::CLOCK_PARAM, ...);

Should be

configParam(CLOCK_PARAM, ...);

shouldn’t matter … the enum is simply a number, not a memory reference.

editing to add that my count shows 21 parameters being defined with configParam and 24 being instantiated with createParam though, so there’s a problem there.

3 Likes

5+ replies under an hour! :grinning::grinning::grinning:

What a community. I’m popping out to run some life errands but look forward to trying some of these suggestions asap.

void process(const ProcessArgs &args) override {
    ...	
}

There is

void process(const ProcessArgs &args) override;

and

void MusicalAnt::process(const ProcessArgs &args) {
	
	
}

Possibly another minor observation.

Don’t think you need this line.

void draw(NVGcontext *vg) override {...};

should be

void draw(const DrawArgs &whatever) override {
    //then e.g.
    nvgBeginPath(whatever.vg);
};

I’m not too sure but I think the call for random::uniform() is changed?!

A quick report to let you know that I’ve built and run your module on Linux. I haven’t got much from it yet, I just started working with it, so I’ll use github to let you know of any issues. I look forward to seeing/hearing what you come up with. :slight_smile: Anyway, here’s what I see in Rack v1.dev:

crashing in json stuff. Those are automatic deletions normally… It’s a pain, but I would build for address sanitizer (asan). It will find a memory allocation error very quickly.

Just ran it and couldn’t make it crash. But I do notice that changing the resolution gives me junk on the screen - is it possible something is wrong there?

also in dataFromJson you don’t check if lastAntPosJ is null before you get the array element from it. Could that perhaps blow you up?

But like I said from playing for 3 minutes I couldn’t make it crash.

The noise when changing resolution is expected for now. I might implement some sort of hilbert curve algorithm to get around this in future tho :slight_smile:

Thanks @Squinky . I’ll check that out. I’ve been struggling with getting debugging happening on my mac. Have attempted valgrind and gdb but no joy. (probably PEBCAK related)

I’ll try lldb ./Rack first as @jerrysv suggested (thanks Jerry) then will look into this address sanitiser stuff after that.

no, valgrind isn’t always macOS compatible (and even when you can find a build that “works”, it’s fickle, and not compatible with Catalina at all), and since you’re on a Mac, you should really be using the compiler and tools it comes with (clang/clang++/lldb) instead of gcc/g++/gdb, so don’t beat yourself up too much about those.

address/memory sanitizers work pretty well, and are a bit nicer to work with imho, but my gut tells me that your issue is going to be either configParam() or draw() like @Coirt suggested (I had missed that one on my quick glance through your code). fix those two, and chances are it will work. either way, I’d put $1 on widget related.

1 Like

Valgrind makes rack run too slow to be be useful. asan seemed quite ok. And found my bug immediately.

1 Like

Hmmm… I was able to add the -g flag into my plugin Makefile alright and test but as soon as I add -fsanitize=address I get:

Could not find module “MusicalAnt” of plugin "AuntyLangtons"

This is similar to another thread I’ve read in which running Rack in dev mode, ./Rack -d changes the default plugins path…

That said, all of the vcvrack.com installed plugins on my Rack account are visible in the plugin library/picker… :thinking: