SimonDanisch / FixedSizeArrays.jl

Julia's generic FixedSizeArray implementation. Can be used for all kinds of Vector constructs
Other
35 stars 20 forks source link

Nondeterministic crash #85

Open blegat opened 8 years ago

blegat commented 8 years ago

I am having a very hard time creating a minimal crashing example for this bug because it is nonderterministic. If I execute 2 times the same code it can crash and then work perfectly. If I had or remove one line that has nothing to do with the crash, it can stop crashing at all (that is what makes it difficult to make a minimal example).

The error I get is

ERROR: LoadError: LoadError: BoundsError: attempt to access ()
  at index [0]
 [inlined code] from tuple.jl:8
 in _fill_tuples_expr at /home/blegat/.julia/v0.5/FixedSizeArrays/src/constructors.jl:4
 in fill_tuples_expr at /home/blegat/.julia/v0.5/FixedSizeArrays/src/constructors.jl:6
 in map at /home/blegat/.julia/v0.5/FixedSizeArrays/src/mapreduce.jl:78
 [inlined code] from /home/blegat/.julia/v0.5/FixedSizeArrays/src/ops.jl:89
 in normalize at /home/blegat/.julia/v0.5/FixedSizeArrays/src/ops.jl:138
 in map! at abstractarray.jl:1293
 in fulldecompose at /home/blegat/.julia/v0.5/Polyhedra/src/decompose.jl:237
 in decompose at /home/blegat/.julia/v0.5/Polyhedra/src/decompose.jl:254
 in call at /home/blegat/.julia/v0.5/GeometryTypes/src/primitives.jl:18
 in include at ./boot.jl:260
 in include_from_node1 at ./loading.jl:392
 in include at ./boot.jl:260
 in include_from_node1 at ./loading.jl:392
 in process_options at ./client.jl:277
 in _start at ./client.jl:377

With the code

A = [-1  0  0;
      0 -4  0;
      0  0 -3;
      1  0  0
      0  2  0
      0  0  3
      1  1  1
     -1  0  0
      0 -1  0
      0  0 -1]

b = [-40;
     -75;
     -33;
     100;
     100;
     100;
     100;
       0;
       0;
       0]

eqs = IntSet([])

include("common.jl")

where common.jl is

using Polyhedra
using CDDLib
using GeometryTypes
using GLVisualize
using GLAbstraction

ine = InequalityDescription(A, b)
poly = CDDPolyhedron{3,Rational{BigInt}}(ine)

w = glscreen()
mesh = GLNormalMesh(poly)
view(visualize(mesh, model=scalematrix(Vec3f0(0.03))), w)
renderloop(w)

The moment it fails is when I do map!(normalize, ns) where ns contains normals. If I replace it with map(normalize, ns), it also fails. What could it be ? Maybe is it because the normals in ns shares Rational{BigInt} using the same reference ? I don't know... Do you have any idea ?

SimonDanisch commented 8 years ago

Are you on a very new version of Julia 0.5?

blegat commented 8 years ago

Not that new: Version 0.5.0-dev+1491 (2015-11-27 16:54 UTC) Commit 41fb1ba (109 days old master)

SimonDanisch commented 8 years ago

so I guess this happens in mesh = GLNormalMesh(poly) ?

blegat commented 8 years ago

Yes, exactly

SimonDanisch commented 8 years ago

can you break this down, so that I can try to reproduce it? Like this I have no chance! Alternatively, you can try to just replace normalize with your own implementation (should be very quick) and see if the problem remains.

blegat commented 8 years ago

Yes I'll try to break this down but as I said, as soon as I change something the problem disappear :( I'll tell you when I have something more precise ;)

blegat commented 8 years ago

I have been able to simplify a bit. It fails 100% of the time with the following code

using Polyhedra
using CDDLib

V = [ 1  0 -1/sqrt(2);
     -1  0 -1/sqrt(2);
      0  1  1/sqrt(2);
      0 -1  1/sqrt(2)]
ext = GeneratorDescription(V)
poly = polyhedron(ext)

using GeometryTypes
mesh = GLNormalMesh(poly)

even if I remplace fulldecompose of Polyhedra/src/decompose.jl by the following:

function fulldecompose{T}(poly::Polyhedron{3,T})
 ntri = 4
 points  = Vector{FixedSizeArrays.Point{3,Float64}}(3*ntri)
 faces   = Vector{GeometryTypes.Face{3,Int,0}}(ntri)
 ns = Vector{GeometryTypes.Normal{3,Float64}}(3*ntri)
 map!(v -> v, ns)
 (points, faces, ns)
end

Surprisingly enough, if I do not allocate points and faces in fulldecompose, it does not fail. I have also tried to execute the code of fulldecompose out of the package Polyhedra but then it does not fail anymore :(

Of course, I realize that it does not make the problem a lot easier to solve... Maybe it will be fixed when Julia 0.5 is released so we might just wait and see :-P