You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using GLMakie
const state = zeros(Float32, 5^2+10^3)
state .= randn(5^2+10^3)
update(state)
const view = @view state[5^2+1:end]
function create_unsafe_vector(view_array)
# Get the pointer to the view array
ptr = pointer(view_array)
# Wrap the pointer into a Julia array without copying
unsafe_vector = unsafe_wrap(Vector{eltype(view_array)}, ptr, length(view_array))
return unsafe_vector
end
const unsafe_view = create_unsafe_vector(view)
const unsafeobs = Observable(unsafe_view)
const viewobs = Observable(view)
fig = Figure()
ax = Axis3(fig[1, 1])
display(fig)
sz = (10,10,10)
allidxs = [1:1000;]
idx2ycoord(size::NTuple{3,T}, idx) where {T} = (T(idx)-T(1)) % size[1] + T(1)
idx2xcoord(size::NTuple{3,T}, idx) where {T} = (floor(T, (idx-T(1))/size[1])) % size[2] + T(1)
idx2zcoord(size::NTuple{3,T}, idx) where {T} = floor(T, (idx-T(1))/(size[1]*size[2])) + T(1)
xs = idx2xcoord.(Ref(sz), allidxs)
ys = idx2ycoord.(Ref(sz), allidxs)
zs = idx2zcoord.(Ref(sz), allidxs)
meshscatter!(ax, xs, ys, zs, markersize = 0.2, color = viewobs)
The above code only works with the unsafeobs, not the viewobs. When using Float64 for the original array there are no problems. I'm getting the following error:
ERROR: MethodError: no method matching GLMakie.GLAbstraction.TextureBuffer(::SubArray{Float32, 1, Vector{Float32}, Tuple{UnitRange{Int64}}, true})
Closest candidates are:
GLMakie.GLAbstraction.TextureBuffer(::GLMakie.GLAbstraction.Texture{T, 1}, ::GLMakie.GLAbstraction.GLBuffer{T}) where T
@ GLMakie ~/.julia/packages/GLMakie/VvhAo/src/GLAbstraction/GLTexture.jl:50
GLMakie.GLAbstraction.TextureBuffer(::GLMakie.GLAbstraction.GLBuffer{T}) where T<:Union{Real, ColorTypes.Colorant, StaticArraysCore.StaticArray{Tuple{N}, T, 1} where {N, T}}
@ GLMakie ~/.julia/packages/GLMakie/VvhAo/src/GLAbstraction/GLTexture.jl:191
GLMakie.GLAbstraction.TextureBuffer(::Vector{T}) where T<:Union{Real, ColorTypes.Colorant, StaticArraysCore.StaticArray{Tuple{N}, T, 1} where {N, T}}
@ GLMakie ~/.julia/packages/GLMakie/VvhAo/src/GLAbstraction/GLTexture.jl:204
The text was updated successfully, but these errors were encountered:
Actually, I just found that even with the unsafeview, updating and then notifying the colors gives weird behavior, where the colors are not updated properly. When the original state has eltype Float64 everything seems to work fine.
The above code only works with the unsafeobs, not the viewobs. When using Float64 for the original array there are no problems. I'm getting the following error:
The text was updated successfully, but these errors were encountered: