@Simeon Is there a reason why spriteMode doesn’t work before setup() anymore. It works before setup() in version 1.5 . Run this and the sprite doesn’t fill the square. Uncomment the spriteMode in setup() and it fills the square. Also, image set and image get require an integer. You can’t set or get the half values for the retina display.
spriteMode(CORNER)
function setup()
--spriteMode(CORNER) -- uncomment this line
img=image(200,200)
setContext(img)
fill(255,0,0)
rect(0,0,200,200)
setContext()
end
function draw()
background(40, 40, 50)
sprite(img,0,0)
stroke(255)
strokeWidth(2)
noFill()
rect(0,0,200,200)
end
I noted the problem with the 3D library and resolved it with the following code:
function __discreteNormal(a,o,...)
local n = select("#",...) -- arg.n
local na,nb
na = vec3(0,0,0)
for k=2,n do
nb = (select(k,...) - a):cross(select(k-1,...) - a) -- (arg[k] - a):cross(arg[k-1] - a)
na = na + nb/nb:lenSqr()
end
na = na:normalize()
if na:dot(a-o) < 0 then
na = -na
end
return na
end
@Bri_G one for the profilers, I think, as to whether select is faster than creating a table.
(I appear to be able to read the beta thread now. Thank you to whoever enabled it. And thank you to @Andrew_Stacey for alerting me to the issue with the 3D library.)
@dave1707 there should be image rawSet and rawGet which access in pixels, instead of points. I’ll have to think about using how to re-enable spriteMode and other graphical style changes outside of setup.
@dave1707, unfortunately my code is about 2000 lines long, but the crash comes from textSize being called many times during draw().
Here’s how it’s being called:
tpt = {}
tpt.widths = {}
tpt.textwidth = function(text)
---[[
if text and type(text) == "string" and #text > 0 then
if type(tpt.widths[text]) == "string" then
return tpt.widths[text]
else
--saveProjectTab("Log", "-- " .. type(text) .. " " .. text .. ": " .. table.concat({string.byte(tostring(text))}, ","))
local x, y = textSize(text)
--saveProjectTab("Log", "--textwidth")
tpt.widths[text] = (x)
return x or 10
end
end
return 0
--[=[
--]]
return 0
--]=]
end
@FLCode I’m not sure what your code is doing, but you said you call textSize many times with draw. So I set up this code that calls textSize and increases the size of str by 1 character per draw. I can run this and let it go with no problems. Apparently the max textSize is 19997. So I don’t think there’s a problem with testSize.
function setup()
str="a"
end
function draw()
background(40, 40, 50)
w,h=textSize(str)
text("Size ".. w,WIDTH/2,HEIGHT/2)
text("Length "..string.len(str),WIDTH/2,HEIGHT/2-50)
str=str.."a"
end
@Simeon I didn’t see scale in the documents for image. I know about rawset and rawget for tables, but rawSet and rawGet for graphics are new to me. I’m just wondering how many other commands are available that don’t show in the docs and how can we find out about them.
Just a quick update on what I’ve found in my code so far. Most of the problems have been related to math.mod() or math.random(). An example is in LightDye’s thread and JMV38’s Loading wheel code here: