FigBug/Gin

gin::PerlinNoise(seed) constructor triggers a jassert

matkatmusic opened this issue · 1 comments

This constructor causes a jassert in juce::ArrayBase:

    PerlinNoise (unsigned int seed)
    {
        juce::Random r (seed);

        for (int i = 0; i <= 255; i++)
            p.add (i);

        shuffleArray (r, p);

        p.addArray (p);
    }

the line in question is:

p.addArray (p);

The jassert being triggered is:

    template <class OtherArrayType>
    void addArray (const OtherArrayType& arrayToAddFrom)
    {
        jassert ((const void*) this != (const void*) &arrayToAddFrom); // can't add from our own elements!

Here is a solution that gets around the jassert:

    PerlinNoise (unsigned int seed)
    {
        juce::Random r (seed);

        for (int i = 0; i <= 255; i++)
            p.add (i);

        shuffleArray (r, p);

        auto copy = p; //insert this line
        
        p.addArray (copy);
    }

Fixed in 14046c6