Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

World age error when displaying PNG images #609

Closed
cormullion opened this issue Jan 4, 2018 · 6 comments
Closed

World age error when displaying PNG images #609

cormullion opened this issue Jan 4, 2018 · 6 comments

Comments

@cormullion
Copy link

In a new Jupyter Notebook, I do this:

using FileIO; display("image/png", FileIO.load("/tmp/image.png"))

and get this error:

MethodError: no method matching show(::IOContext{Base64EncodePipe}, ::MIME{Symbol("image/png")}, 
::Array{ColorTypes.RGB4{FixedPointNumbers.Normed{UInt8,8}},2})

The applicable method may be too new: running in world age 21815, while current
world is 21860.  Closest candidates are: show(::IO,
::MIME{Symbol("image/png")}, ::AbstractArray{C<:ColorTypes.Colorant,2};
minpixels, maxpixels, mapi) where C<:ColorTypes.Colorant at
/Users/me/.julia/v0.6/Images/src/showmime.jl:23 (method too new to be called
from this world context.) show(::IO, ::MIME{Symbol("text/csv")}, ::Any) at
datafmt.jl:707 show(::IO, ::MIME{Symbol("text/tab-separated-values")}, ::Any)
at datafmt.jl:708 ...

Stacktrace: [1] limitstringmime(::MIME{Symbol("image/png")},
::Array{ColorTypes.RGB4{FixedPointNumbers.Normed{UInt8,8}},2}) at
/Users/me/.julia/v0.6/IJulia/src/inline.jl:31 [2]
display(::IJulia.InlineDisplay, ::MIME{Symbol("image/png")},
::Array{ColorTypes.RGB4{FixedPointNumbers.Normed{UInt8,8}},2}) at
/Users/me/.julia/v0.6/IJulia/src/inline.jl:41 [3]
display(::MIME{Symbol("image/png")},
::Array{ColorTypes.RGB4{FixedPointNumbers.Normed{UInt8,8}},2}) at
./multimedia.jl:208 [4] display(::String,
::Array{ColorTypes.RGB4{FixedPointNumbers.Normed{UInt8,8}},2}) at
./multimedia.jl:126 [5] include_string(::String, ::String) at ./loading.jl:515

But then when I evaluate the cell again, it works correctly; so it only generates this error the first time it runs in a notebook.

I don't really understand 'world age errors'... :(

Julia v0.6, IJulia.jl 1.6.2

@KristofferC
Copy link
Sponsor Member

KristofferC commented Jan 4, 2018

I think the problem is that FileIO will load Images, but we will not hit top level scope until the call to display is executed so the world age haven't updated.

I think we can either add some invokelatest in IJulia like:

diff --git a/src/inline.jl b/src/inline.jl
index 2e82131..7cc1ee3 100644
--- a/src/inline.jl
+++ b/src/inline.jl
@@ -21,14 +21,14 @@ function limitstringmime(mime::MIME, x)
         if israwtext(mime, x)
             return String(x)
         else
-            show(IOContext(buf, :limit=>true), mime, x)
+            Base.invokelatest(show, IOContext(buf, :limit=>true), mime, x)
         end
     else
         b64 = Base64EncodePipe(buf)
         if isa(x, Vector{UInt8})
             write(b64, x) # x assumed to be raw binary data
         else
-            show(IOContext(b64, :limit=>true), mime, x)
+            Base.invokelatest(show, IOContext(b64, :limit=>true), mime, x)
         end
         close(b64)
     end

or document this somehow.

@cormullion
Copy link
Author

Interesting. It would be nice to have it fixed in IJulia, of course! Although I'm happy to insert some (similar?) fix into Luxor.preview() if not...

@KristofferC
Copy link
Sponsor Member

KristofferC commented Jan 4, 2018

You could try change e.g: https://github.com/JuliaGraphics/Luxor.jl/blob/2fec4728ef3750ba203bda0d2eb0afff4626c5a3/src/Luxor.jl#L338

to

Base.invokelatest(display, "image/png", load(currentdrawing.filename))

and see if it works.

@stevengj
Copy link
Member

stevengj commented Jan 4, 2018

Seems similar to JuliaIO/FileIO.jl#142 ... it seems like there is a fundamental difficulty (not IJulia-specific) with how FileIO loads modules on-demand in the context of a single eval.

@cormullion
Copy link
Author

@KristofferC That (Luxor) fix seems to work fine! It's not time critical, so I can't see any drawbacks. Thanks! I'll leave this issue open.

@stevengj
Copy link
Member

stevengj commented Jan 4, 2018

It's not an IJulia-specific issue; the same thing would presumably happen in the REPL if you have a display backend capable of showing image/png.

@stevengj stevengj closed this as completed Jan 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants