# Stack overflow when reshaping image array

**URL:** <https://discourse.julialang.org/t/stack-overflow-when-reshaping-image-array/45927>\
**Category:** General Usage\
**Created:** [September 2, 2020, 1:52am UTC](https://discourse.julialang.org/t/stack-overflow-when-reshaping-image-array/45927 "2020-09-02T01:52:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![timmor](https://avatars.discourse-cdn.com/v4/letter/t/e19b73/32.png) [@timmor](https://discourse.julialang.org/u/timmor)\
**Post date:** [September 2, 2020, 1:52am UTC](https://discourse.julialang.org/t/stack-overflow-when-reshaping-image-array/45927/1 "2020-09-02T01:52:34Z")

</div>

I’m trying to read a few frames of video from a file and reshape the data into a three-dimensional array. I’m getting an infinite recursion when reshaping the array.

```julia
using VideoIO
io = VideoIO.testvideo("ladybird")
f = VideoIO.openvideo(io)
viddata = read(f)[:]
for i = 1:10 # read just a few frames
	append!(viddata, read(f))
end
vid = reshape(viddata, f.height, f.width, :) # stack overflow here

ERROR: StackOverflowError:
Stacktrace:
 [1] reshape(::Array{ColorTypes.RGB{FixedPointNumbers.Normed{UInt8,8}},1}, ::Tuple{Int32,Int32,Colon}) at /home/username/.julia/packages/OffsetArrays/46NUD/src/OffsetArrays.jl:111 (repeats 79984 times)

```

I don’t understand why OffsetArrays is getting involved here. My data type is

```julia
typeof(viddata)
Array{ColorTypes.RGB{FixedPointNumbers.Normed{UInt8,8}},1}

```

Any thoughts on what’s gone wrong?  
Thanks.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [September 2, 2020, 3:14am UTC](https://discourse.julialang.org/t/stack-overflow-when-reshaping-image-array/45927/2 "2020-09-02T03:14:24Z")

</div>

```julia
julia> vid = reshape(viddata, Int64(f.height), Int64(f.width), :); size(vid)
(1080, 1920, 11)

```

this works, this is almost certainly a bug you should report, the `f.height` was an `Int32` which caused the bug, this line creates the stack overflow in the end

[https://github.com/JuliaArrays/OffsetArrays.jl/blob/ff0d630caf999fbe6c06562deb4106d65a86de6c/src/OffsetArrays.jl#L116](https://github.com/JuliaArrays/OffsetArrays.jl/blob/ff0d630caf999fbe6c06562deb4106d65a86de6c/src/OffsetArrays.jl#L116)

---

<div class="post-metadata">

**Author:** ![timmor](https://avatars.discourse-cdn.com/v4/letter/t/e19b73/32.png) [@timmor](https://discourse.julialang.org/u/timmor)\
**Post date:** [September 2, 2020, 5:33am UTC](https://discourse.julialang.org/t/stack-overflow-when-reshaping-image-array/45927/3 "2020-09-02T05:33:05Z")

</div>

Thanks, that’s a good workaround. I’ll report the bug.
