ReadBlock limitation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
There is a very bothersome limitation in <Interface:MemStream>.readBlock
And that is that it fails if the close token is more than 5120 characters from the open token, the function returns undefined.
I've had problems for a couple years with this limitation. My workaround has been to use this basic solution from http://forums.cgsociety.org/archive/index.php/t-1082753.html
fn readBlock ms =
(
local p1 = "("
local p2 = ")"
local s1 = "\""
local s2 = "\\"
local s3 = "-"
local s4 = "/"
local s5 = "*"
local s6 = "\n"
local token = ms.readChar()
while not ms.eos() and not token[1] == p1 do
token = ms.readToken()
local ss = stringStream ""
format token to:ss
local n = 1
local inString = false
local inComment1 = false
local inComment2 = false
local last1 = ""
local last2 = ""
while not ms.eos() and n > 0 do (
local c = ms.readChar()
format "%" c to:ss
if not inString and not inComment1 and not inComment2 then (
case c of (
s1: if last1 != s2 or last2 == s2 then inString = true
s3: if last1 == s3 then inComment1 = true
s5: if last1 == s4 then inComment2 = true
p1: n += 1
p2: n -= 1
)
) else (
case c of (
s1: if inString and last1 != s2 or last2 == s2 then inString = false
s6: inComment1 = false
s4: if inComment2 and last1 == s5 then inComment2 = false
)
)
last2 = last1
last1 = c
)
if n > 0 then undefined else ss as string
)
But this code has a serious flaw. It very often generates an Unknown System Exception. My guess is that it goes past the end of the string.
Anyone have any working solution for this that is fool-proof? I really can't understand this hard-coded limitation of 5120 characters.
Shawn Olson
Developer of Wall Worm
3ds Max plugins and Scripts
3ds Max 4/Gmax - 3ds Max 2020
Mudbox 2009-2019
Windows 10 x64
i7 8700K
64GB RAM
Geforce 1080ti