Skip to content

A segfault with member functions #493

@JanisErdmanis

Description

@JanisErdmanis

Hello. When I tried to execute example notebook of RegionTrees.jl package I found a segfault on my system (Ubuntu 18.04). Purifying the crashing code I came up with this one:

SEGFAULT = true
using StaticArrays

struct TwosArray{N, T, L} <: StaticArray{NTuple{N, 2}, T, N}
    data::NTuple{L, T}
end
Base.getindex(b::TwosArray, i::Int) = b.data[i]

struct SignedDistanceRefinery{F <: Function} # <: AbstractRefinery 
    signed_distance_func::F
end

function refine_data(refinery::SignedDistanceRefinery, v) 
    refinery.signed_distance_func.(v)
end

signed_distance(x) = sqrt(sum(x.^2))
refinery = SignedDistanceRefinery(signed_distance)

vp = TwosArray{1,SArray{Tuple{2},Float64,1,2},2}((SVector(1.,2.),SVector(3.,1.)))

!SEGFAULT || refinery.signed_distance_func.(vp)
refine_data(refinery,vp)

Interestingly to cause a segfault both last two lines need to be present which also commute with themselves.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions