View Issue Details

IDProjectCategoryView StatusLast Update
0000347luatexluatex bugpublic2010-03-12 15:46
Reporterpatrick Assigned ToTaco  
PrioritynormalSeveritycrashReproducibilityalways
Status closedResolutionfixed 
Platformi386 64bit?!?OSMac OS XOS Version10.6
Fixed in Version0.51.0 
Summary0000347: attempt to index a thread value
DescriptionWith the current version (and older ones, I had the problem last year end of september), I get the error
"attempt to index a thread value". This happens when I use font.each() or font.fonts[x].

To reproduce the problem you need the file "texgyreheros-bold.otf" in the kpathsea search path (local folder).

run with luatex --ini thisfile.tex
-----
\catcode`\{=1
\catcode`\}=2
\directlua {tex.enableprimitives('',tex.extraprimitives ())}
\pdfoutput = 1

\directlua{
function define_font(name, size)
  local ttffont

  local filename_path
  local lookup_codepoint_by_name = {}
  local lookup_codepoint_by_number = {}

  filename_path = kpse.find_file(name)
  if not filename_path then return false, "file not found" end

  ttffont = fontloader.to_table(fontloader.open(filename_path))
  if ttffont == nil then return false, "problem" end

  
  for i = 1,#ttffont.glyphs do
    local g=ttffont.glyphs[i]

    lookup_codepoint_by_name[g.name] = ttffont.map.backmap[i]
    lookup_codepoint_by_number[i] = ttffont.map.backmap[i]
  end


  if (size < 0) then size = (- 655.36) * size end
  if ttffont.units_per_em == 0 then ttffont.units_per_em = 1000 end
  local mag = size / ttffont.units_per_em


  local f = { }
  f.characters = { }
  f.fontloader = ttffont
  f.name = ttffont.fontname
  f.fullname = ttffont.fontname
  f.designsize = size
  f.size = size
  f.direction = 0
  f.filename = filename_path
  f.type = 'real'
  f.encodingbytes = 2
  f.tounicode = 1
  
  f.parameters = { }
  f.parameters.slant = 0
  f.parameters.space = 0.25 * size
  f.parameters.space_stretch = 0.3 * size
  f.parameters.space_shrink = 0.1 * size
  f.parameters.x_height = 0.4 * size
  f.parameters.quad = 1.0 * size
  f.parameters.extra_space = 0
  
  f.format = "opentype"
  f.embedding = "subset"
  f.cidinfo = ttffont.cidinfo


  for i=1,#ttffont.glyphs do
    local glyph = ttffont.glyphs[i]
    local codepoint = lookup_codepoint_by_number[i]

    f.characters[codepoint] = {
        index = i,
        width = glyph.width * mag,
        name = glyph.name,
      }
    if glyph.boundingbox[4] then f.characters[codepoint].height = glyph.boundingbox[4] * mag end
    if glyph.boundingbox[2] then f.characters[codepoint].depth = -glyph.boundingbox[2] * mag end

  end

  return true,f
end


function call(...)
  local ret = { pcall(...) }
  if ret[1]==false then
    print("error:" .. tostring(ret[2]))
    exit()
  end
  return unpack(ret,2)
end


function main_loop( )
  call(foo)
  coroutine.yield("end")
end

function foo()
  local ok,f = define_font("texgyreheros-bold.otf",65782 * 10)
  print(ok)
  font.define(f)
  
  for i,f in font.each() do
    % this raises an error
  end
end

co = coroutine.create(main_loop)
a,b=coroutine.resume(co) tex.sprint(b or "")
}

\end
-----
Additional InformationOutput:

~/tmp$ ls
fonttest.tex texgyreheros-bold.otf

~/tmp$ luatex --ini fonttest.tex
This is LuaTeX, Version beta-0.51.0-2010031113 (INITEX)
(./fonttest.textrue
error:attempt to index a thread value

! Missing number, treated as zero.
<to be read again>
                   >
...
l.106 }
       
TagsNo tags attached.

Activities

Taco

2010-03-12 09:48

administrator   ~0000468

Fixed by #3469: font.define() was always using the global lua thread.

But this raises a subtle point: font.define() by default stores a reference to the table you gave it in the lua registry. This table reference is thread-local,
so if you plan to call font.each() or font.fonts[x] via coroutines, it will
be better to turn that caching feature off:

  font.cache = 'no'

Actually, the error 'attempt to index a thread value' is a little bit misleading here: invalid registry references always look like 'thread values' to the lua interpreter.

Issue History

Date Modified Username Field Change
2010-03-12 00:05 patrick New Issue
2010-03-12 09:48 Taco Note Added: 0000468
2010-03-12 09:48 Taco Status new => resolved
2010-03-12 09:48 Taco Resolution open => fixed
2010-03-12 09:48 Taco Assigned To => Taco
2010-03-12 15:46 Taco Fixed in Version => 0.51.0
2010-03-12 15:46 Taco Status resolved => closed