meg768 / rpi-ws281x

rpi-ws281x
22 stars 26 forks source link

segmentation fault / free(): invalid pointer / Check failed: !backing_store->is_wasm_memory(). #21

Open abstract-entity opened 2 years ago

abstract-entity commented 2 years ago

Hello,

I've try your PR (adding dependency in package.json: "rpi-ws281x": "git+https://github.com/meg768/rpi-ws281x.git#master"), this is working 1 time on 10,

I got 'segmentation fault' or 'free(): invalid pointer' error randomly.

segmentation fault Or

/home/pi/christmas/node_modules/rpi-ws281x/index.js:100 addon.render(pixels, this.map); ^

Error: Size of pixel mapping does not match. at Module.render (/home/pi/christmas/node_modules/rpi-ws281x/index.js:100:19) at Timeout._onTimeout (/home/pi/christmas/random-red-white.js:27:20) at listOnTimeout (internal/timers.js:554:17) at processTimers (internal/timers.js:497:7) free(): invalid pointer Aborted Or

#

Fatal error in , line 0

Check failed: !backing_store->is_wasm_memory().

# # #

FailureMessage Object: 0xbe8e5c30

Illegal instruction

Maybe linked from https://github.com/meg768/rpi-ws281x/issues/12 or https://github.com/meg768/rpi-ws281x/issues/11

Let me know how i can help, i'm very unfamilliar with c++

rip3rs commented 2 years ago

I haven't had any issues, could it be that you have an older package-lock?

Perhaps a repo with the project giving those errors, because I cannot seem to replicate :(

meg768 commented 2 years ago

Well, there are no pull requests at the moment. Currently, I do not have the ability to test anything. When a pull request arrives I will merge and publish.

abstract-entity commented 2 years ago

I was testing this PR: https://github.com/meg768/rpi-ws281x/pull/20 . https://github.com/rip3rs add Raspberry Pi 4 compatibility. I've tested exactly the same package.json and code on raspberry 2, it's working like a charm.

Here the package.json:

{
  "name": "christmas-string",
  "version": "0.0.0",
  "private": true,
  "dependencies": {
    "rpi-ws281x": "git+https://github.com/meg768/rpi-ws281x.git#master",
    "rxjs": "~6.6.0",
    "tslib": "^2.0.0"
  },
  "devDependencies": {
    "codelyzer": "^6.0.0",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~4.0.2"
  }
}

I've reset package-lock and node_module:

pi@raspberrypi:~/christmas $ rm -rf package-lock.json node_modules*
pi@raspberrypi:~/christmas $ npm install
npm WARN deprecated tslint@6.1.3: TSLint has been deprecated in favor of ESLint. Please see https://github.com/palantir/tslint/issues/4534 for more information.

> rpi-ws281x@1.0.36 install /home/pi/christmas/node_modules/rpi-ws281x
> node-gyp rebuild

make: Entering directory '/home/pi/christmas/node_modules/rpi-ws281x/build'
  CXX(target) Release/obj.target/rpi-ws281x/src/addon.o
  CC(target) Release/obj.target/rpi-ws281x/src/rpi_ws281x/ws2811.o
  CC(target) Release/obj.target/rpi-ws281x/src/rpi_ws281x/pwm.o
  CC(target) Release/obj.target/rpi-ws281x/src/rpi_ws281x/dma.o
  CC(target) Release/obj.target/rpi-ws281x/src/rpi_ws281x/mailbox.o
  CC(target) Release/obj.target/rpi-ws281x/src/rpi_ws281x/rpihw.o
  CC(target) Release/obj.target/rpi-ws281x/src/rpi_ws281x/pcm.o
  SOLINK_MODULE(target) Release/obj.target/rpi-ws281x.node
  COPY Release/rpi-ws281x.node
make: Leaving directory '/home/pi/christmas/node_modules/rpi-ws281x/build'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN @angular/core@9.0.0 requires a peer of tslib@^1.10.0 but none is installed. You must install peer dependencies yourself.
npm WARN @angular/compiler@9.0.0 requires a peer of tslib@^1.10.0 but none is installed. You must install peer dependencies yourself.

added 72 packages from 98 contributors and audited 72 packages in 30.411s

3 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

The code below reproduce the error:

var ws281x = require('rpi-ws281x');

class Example {

    constructor() {
        this.config = {leds:100};
        ws281x.configure(this.config);
    }

    run() {
        var pixels = new Uint32Array(this.config.leds);

        setInterval(() => {

            pixels.forEach( ( pixel, index ) => {
                if ( pixel === 0xffffff ) {
                    pixels[index] = 0xffcccc;
                } else if ( pixel === 0xffcccc ) {
                    pixels[index] = 0xff9999;
                } else if ( pixel === 0xff9999 ) {
                    pixels[index] = 0xff6666;
                } else {
                    pixels[index] = Math.random() > .05 ? 0xff0000 : 0xffffff;
                }
            });
            ws281x.render(pixels);
        }, 50);
    }
};

var example = new Example();

function delay(time) {
    return new Promise(resolve => setTimeout(resolve, time));
  }

delay(1000).then(() => example.run());

Changing delay between renders seems to not reduce error occurence.

pi@raspberrypi:~/christmas $ sudo node random-red-white.js
Segmentation fault
pi@raspberrypi:~/christmas $ sudo node random-red-white.js
Segmentation fault
pi@raspberrypi:~/christmas $ sudo node random-red-white.js
^C
pi@raspberrypi:~/christmas $ sudo node random-red-white.js
^C
pi@raspberrypi:~/christmas $ sudo node random-red-white.js
Segmentation fault
pi@raspberrypi:~/christmas $ sudo node random-red-white.js
^C
pi@raspberrypi:~/christmas $ sudo node random-red-white.js

#
# Fatal error in , line 0
# Check failed: !backing_store->is_wasm_memory().
#
#
#
#FailureMessage Object: 0xbeba1c30
Illegal instruction
pi@raspberrypi:~/christmas $ sudo node random-red-white.js
Segmentation fault
pi@raspberrypi:~/christmas $ sudo node random-red-white.js
corrupted double-linked list
pi@raspberrypi:~/christmas $ sudo node random-red-white.js
#
# Fatal error in , line 0
# Check failed: map_object.IsMap().
#
#
#
#FailureMessage Object: 0xbeec6260

Version of the raspberry: Raspberry Pi 4B, 2 GB RAM, WiFi & BT

pi@raspberrypi:~/christmas $ cat /etc/debian_version
10.4
pi@raspberrypi:~/christmas $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
pi@raspberrypi:~/christmas $ uname -a
Linux raspberrypi 5.4.51-v7l+ #1333 SMP Mon Aug 10 16:51:40 BST 2020 armv7l GNU/Linux
pi@raspberrypi:~/christmas $ cat /proc/cpuinfo
processor       : 0
model name      : ARMv7 Processor rev 3 (v7l)
BogoMIPS        : 108.00
Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xd08
CPU revision    : 3

processor       : 1
model name      : ARMv7 Processor rev 3 (v7l)
BogoMIPS        : 108.00
Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xd08
CPU revision    : 3

processor       : 2
model name      : ARMv7 Processor rev 3 (v7l)
BogoMIPS        : 108.00
Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xd08
CPU revision    : 3

processor       : 3
model name      : ARMv7 Processor rev 3 (v7l)
BogoMIPS        : 108.00
Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xd08
CPU revision    : 3

Hardware        : BCM2711
Revision        : b03114
Serial          : 100000007dbbeee5
Model           : Raspberry Pi 4 Model B Rev 1.4

IMG_20211018_105803

rip3rs commented 2 years ago

I have recently started having problems of segmentation fault.

I believe this has to do with the other module that this repo is using. The RPI 4 is strange... I will be looking into this as soon as I get some free time (can take some time :( )

abstract-entity commented 2 years ago

I have recently started having problems of segmentation fault.

I believe this has to do with the other module that this repo is using. The RPI 4 is strange... I will be looking into this as soon as I get some free time (can take some time :( )

I'm trying to define which party of the code is causing problem with my very fresh experience in c++ ! i've updated the code like that, to see exactly which line cause the bug, and i got different lines involved for each message:

NAN_METHOD(Addon::render)
{
    Nan::HandleScope();
cout << "1" << endl;
    if (info.Length() != 2)
    {
        return Nan::ThrowError("render() requires pixels and pixel mapping arguments.");
    }
cout << "2" << endl;
    if (!info[0]->IsUint32Array())
        return Nan::ThrowError("render() requires pixels to be an Uint32Array.");
cout << "3" << endl;
    if (!info[1]->IsUint32Array())
        return Nan::ThrowError("render() requires pixels mapping to be an Uint32Array.");
cout << "4" << endl;
    v8::Local<v8::Uint32Array> array = info[0].As<v8::Uint32Array>();
    v8::Local<v8::Uint32Array> mapping = info[1].As<v8::Uint32Array>();
cout << "5" << endl;
    //if ((uint32_t)(array->Buffer()->GetBackingStore()->ByteLength()) != (uint32_t)(4 * ws2811.channel[0].count))
    //    return Nan::ThrowError("Size of pixels does not match.");
    if ((uint32_t)(mapping->Buffer()->GetBackingStore()->ByteLength()) != (uint32_t)(4 * ws2811.channel[0].count))
        return Nan::ThrowError("Size of pixel mapping does not match.");
cout << "6" << endl;
    uint32_t *pixels = (uint32_t *)array->Buffer()->GetBackingStore()->Data();
cout << "7" << endl;
    uint32_t *map = (uint32_t *)mapping->Buffer()->GetBackingStore()->Data();
cout << "8" << endl;
    uint32_t *leds = ws2811.channel[0].leds;
cout << "9" << endl;

    for (int i = 0; i < ws2811.channel[0].count; i++)
    {
        leds[i] = pixels[map[i]];
    }
cout << "10" << endl;
    ws2811_render(&ws2811);
cout << "11" << endl;
    info.GetReturnValue().Set(Nan::Undefined());
};

Error 1:

pi@raspberrypi:~/christmas/node_modules/rpi-ws281x $ sudo node ../../random-red-white.js
1
2
3
4
5
6
7
8
9
10
11
1
2
3
4
5
6

#
# Fatal error in , line 0
# Check failed: !backing_store->is_wasm_memory().
#
#
#
#FailureMessage Object: 0xbe942be8
Illegal instruction

Error 2:

pi@raspberrypi:~/christmas/node_modules/rpi-ws281x $ sudo node ../../random-red-white.js
1
2
3
4
5
6
7
8
9
10
11
1
2
3
4
5
/home/pi/christmas/node_modules/rpi-ws281x/index.js:100
            addon.render(pixels, this.map);
                  ^

Error: Size of pixel mapping does not match.
    at Module.render (/home/pi/christmas/node_modules/rpi-ws281x/index.js:100:19)
    at Timeout._onTimeout (/home/pi/christmas/random-red-white.js:26:20)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7)

Error 3:

pi@raspberrypi:~/christmas/node_modules/rpi-ws281x $ sudo node ../../random-red-white.js
1
2
3
4
5
6
7
8
9
10
11
1
2
3
4
5
6
7
8
9
Segmentation fault
rip3rs commented 2 years ago

if you change from PWM to PCM it seems to disappear the segmentation fault.

abstract-entity commented 2 years ago

if you change from PWM to PCM it seems to disappear the segmentation fault.

I don't know how to activate PCM, but i try to use GPIO 21 (PIN 40) known as PCM GPIO, and i still have segmentation fault.