Jump to content




Reading bytes


  • You cannot reply to this topic
42 replies to this topic

#21 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 26 July 2018 - 06:08 AM

This is the change I would go with (around line 399):

    StringStream = {
        str = table.concat(output),
        read = function(self, num)
            num = num or 1
            local toreturn = self.str:sub(1, num)
            self.str = self.str:sub(num + 1)
            return toreturn
        end  
    }


#22 emanuel12324

  • Members
  • 28 posts

Posted 26 July 2018 - 07:20 PM

I tried that before too, also to no avail. The error I get is "imgtest:354: Unsupported filter type: " which is because it doesn't seem to read anything on line 332. Not sure why though.

#23 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 27 July 2018 - 05:49 AM

StringStream.read() is returning an incorrect data type - strings, instead of the numeric values that seem to be expected. Better to rig it to work entirely with numbers:

    printV("Deflating...")
    deflate.inflate_zlib {
        input = chunkData.IDAT.data,
        output = function(byte)
            output[#output+1] = byte  --# Ditch the string.char call here
        end,
        disable_crc = true
    }

    local callCount = 1

    StringStream = {
        read = function(self, num)
            num = num or 1
            local start, fin = callCount, callCount + (num or 1) - 1
            callCount = callCount + num
            return unpack(output, start, fin)
        end  
    }

This is why you're not seeing a "filter type" in that error message, as the filterType variable either currently holds a value that can't be rendered as a character (not so much of a problem, but less likely), or it's just an empty string (very much a problem, and unfortunately more likely).

If you find the latter to be true (and the error starts telling you the filter type is nil), that'd imply that the deflate.inflate_zlib() call on line 392 isn't actually putting any data into the "output" table. In that case, first check that the table parameters used in the inflate call are formatted correctly, and then check whether chunkData.IDAT.data actually holds some data.

Edited by Bomb Bloke, 27 July 2018 - 06:29 AM.


#24 emanuel12324

  • Members
  • 28 posts

Posted 28 July 2018 - 08:13 PM

I now get "imgtest:332: attempt to call nil"

#25 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 29 July 2018 - 03:01 AM

Well, assuming that line is still only trying to call readByte(), I suppose you could go and check to see whether you've accidentally deleted that function's definition.

#26 emanuel12324

  • Members
  • 28 posts

Posted 31 July 2018 - 09:19 PM

The function readByte() still exists and is declared before the getPixelRow() function.

#27 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 01 August 2018 - 03:38 AM

If that's true, then 332 has changed since I've seen it last. I'm afraid my telepathy is failing me, so I can't comment further without access to the current version of the code.

#28 emanuel12324

  • Members
  • 28 posts

Posted 02 August 2018 - 02:41 PM

Ah BB, that infallible sense of humor of yours...
Code: https://pastebin.com/NUwwJNcW

#29 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 03 August 2018 - 02:51 AM

That code won't produce that error on that line. Check that you're running the correct copy of your script file.

By the way, digging a bit further I notice you're omitting DelusionalLogic's copyright notice. Be sure to include it in all copies of your code that include this work.

#30 emanuel12324

  • Members
  • 28 posts

Posted 03 August 2018 - 05:53 PM

Yeah, I had cut it out temporarily to have less clutter, but in the end I plan on having all of the png library in it's own file with the appropriate copyright info.

Anyway, this is the code I am running as I uploaded it to pastebin via the in game pastebin script. So what else could this be?

#31 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 04 August 2018 - 01:01 AM

The only other option is that you mixed up your error messages.

#32 emanuel12324

  • Members
  • 28 posts

Posted 04 August 2018 - 05:17 PM

While I'm not really sure what you mean by mixing up my error messages, I can provide a screenshot of my terminal.
https://ibb.co/mosXVe

#33 emanuel12324

  • Members
  • 28 posts

Posted 08 August 2018 - 02:35 PM

Any ideas?

#34 valithor

  • Members
  • 1,053 posts

Posted 08 August 2018 - 07:11 PM

View Postemanuel12324, on 08 August 2018 - 02:35 PM, said:

Any ideas?

line 332:
local filterType = readByte(stream)

Line 332 will not cause that error as bomb bloke said. Make sure line 332 is that line in the program you tried to run as well. If it is not then post your code to pastebin again give us the link here.

Edited by valithor, 08 August 2018 - 07:12 PM.


#35 emanuel12324

  • Members
  • 28 posts

Posted 08 August 2018 - 08:05 PM

Well this is why I'm so troubled. The pastebin posted above is the exact code I'm using and it errors on that line. I have done everything from renaming the file to closing and reopening my world to relaunching my game. My suspicion is that the attempt to call nil isn't actually on line 332, but instead when readByte() tries to call StringStream:read()

#36 Luca_S

  • Members
  • 407 posts
  • LocationGermany

Posted 08 August 2018 - 08:43 PM

View Postemanuel12324, on 08 August 2018 - 08:05 PM, said:

Well this is why I'm so troubled. The pastebin posted above is the exact code I'm using and it errors on that line. I have done everything from renaming the file to closing and reopening my world to relaunching my game. My suspicion is that the attempt to call nil isn't actually on line 332, but instead when readByte() tries to call StringStream:read()

If that was the case, trace would show it to you.

Edit: Just checked myself, in line 332 you are calling readByte(), which calls stream.read(stream).
However stream.read requires 2 Arguments, the stream and the number of bytes to read, the second one is not passed to it.

Edit 2: Also BB already told you about that error, which further makes me believe, that you are not providing us your current code.

Edited by Luca_S, 08 August 2018 - 08:59 PM.


#37 emanuel12324

  • Members
  • 28 posts

Posted 09 August 2018 - 03:13 AM

I will once again post my code here, but you will see it has not changed since my most recent upload. I suspect you are not looking at the most recent paste that I posted. And about trace, well for whatever reason, it never shows me anything at all. Even the expected prints from my code don't show up.

#38 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 09 August 2018 - 04:39 AM

View PostLuca_S, on 08 August 2018 - 08:43 PM, said:

View Postemanuel12324, on 08 August 2018 - 08:05 PM, said:

My suspicion is that the attempt to call nil isn't actually on line 332, but instead when readByte() tries to call StringStream:read()

If that was the case, trace would show it to you.

If that were the case, the error would directly point to line 171, where StringStream:read() is called: there wouldn't be any need to use trace to get that info. We're only interested in what's at the top of the stack, not what's lower down.

View PostLuca_S, on 08 August 2018 - 08:43 PM, said:

However stream.read requires 2 Arguments, the stream and the number of bytes to read, the second one is not passed to it.

It's been changed so that the second argument is optional. Even if it hadn't, though, that still wouldn't trigger the stated error on the stated line.

View Postemanuel12324, on 09 August 2018 - 03:13 AM, said:

Even the expected prints from my code don't show up.

This is another strong indication that you're not running the script file you think you're running.

How are you uploading the code to pastebin - with the "pastebin put" command, or by manually copying the file out of the computer's folder within your world save?

In the latter case, I'd say there's a good chance you're looking at the wrong computer folder!

#39 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 09 August 2018 - 05:08 AM

View PostBomb Bloke, on 09 August 2018 - 04:39 AM, said:

If that were the case, the error would directly point to line 171, where StringStream:read() is called: there wouldn't be any need to use trace to get that info. We're only interested in what's at the top of the stack, not what's lower down.
Not always. As it's used as a tail call, readByte will have exited before StringStream.read is actually called, meaning the error location will attributed to wherever readByte is called instead.

Edited by SquidDev, 09 August 2018 - 05:09 AM.


#40 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 09 August 2018 - 06:38 AM

Ah, well spotted.

As for why it's erroring at all, it occurred to me that, in the unlikely event that emanuel is running the posted code, the error may be coming from another file. For example, if deflatelua is rigged to run a second copy of imgtest buried in a subfolder, then that could crash before the primary copy does.

Of course, that would be a very difficult mistake to make accidentally!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users