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

Bug in the write function when state change after 255 identical states #12

Open
Lswbanban opened this issue Mar 10, 2020 · 0 comments
Open

Comments

@Lswbanban
Copy link

Lswbanban commented Mar 10, 2020

I guess the write function is bugged if you have exactly 255 zero to write, and then the next state the 256th character is a 1 (or vice versa, i.e. if you switch state after exactly 255 count).

The fix is easy: in the else of the "if c==state", add another test before dumping, the test should be: "if ctr > 0:", otherwise you will write a state with zero count, and actually may shift the whole data.

The whole code becomes:

for c in voxels_flat:
        if c==state:
            ctr += 1
            # if ctr hits max, dump
            if ctr==255:
                fp.write(chr(state))
                fp.write(chr(ctr))
                ctr = 0
        else:
            # if switch state, dump
            if ctr > 0:
                fp.write(chr(state))
                fp.write(chr(ctr))
            state = c
            ctr = 1
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

1 participant