Skip to content

Commit 9e5bee7

Browse files
author
Chris Foster
committed
Fix bug in ply_type_name() for empty list properties
1 parent c9625a4 commit 9e5bee7

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/io.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ ply_type_name(::Int64) = "int64"
4444
ply_type_name(::Float32) = "float32"
4545
ply_type_name(::Float64) = "float64"
4646

47-
ply_type_name(A::AbstractArray) = ply_type_name(A[1])
47+
typealias PlyNativeType Union{UInt8,UInt16,UInt32,UInt64,Int8,Int16,Int32,Int64,Float32,Float64}
48+
49+
ply_type_name{T<:PlyNativeType}(A::AbstractArray{T}) = ply_type_name(T)
50+
51+
ply_type_name(A::AbstractArray) = !isempty(A) ? ply_type_name(A[1]) :
52+
error("Unknown ply element type name for empty array of type $(typeof(A))")
4853

4954

5055
const _host_is_little_endian = (ENDIAN_BOM == 0x04030201)

test/runtests.jl

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ using Base.Test
2121
push!(ply, PlyComment("Final comment"))
2222

2323
buf = IOBuffer()
24-
save_ply(ply, buf, ascii=true, )
24+
save_ply(ply, buf, ascii=true)
2525
str = takebuf_string(buf)
2626
open("simple_test_tmp.ply", "w") do fid
2727
write(fid, str)
@@ -50,6 +50,32 @@ using Base.Test
5050
"""
5151
end
5252

53+
@testset "empty elements" begin
54+
ply = Ply()
55+
56+
push!(ply, PlyElement("A", ArrayProperty("x", UInt8[])))
57+
push!(ply, PlyElement("B", ListProperty("a_list", Vector{Int64}[[], [], []])))
58+
59+
buf = IOBuffer()
60+
save_ply(ply, buf, ascii=true)
61+
str = takebuf_string(buf)
62+
open("empty_test_tmp.ply", "w") do fid
63+
write(fid, str)
64+
end
65+
@test str ==
66+
"""
67+
ply
68+
format ascii 1.0
69+
element A 0
70+
property uint8 x
71+
element B 3
72+
property list int32 int64 a_list
73+
end_header
74+
0
75+
0
76+
0
77+
"""
78+
end
5379

5480
@testset "roundtrip" begin
5581
@testset "ascii=$test_ascii" for test_ascii in [false, true]

0 commit comments

Comments
 (0)