Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8676611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:14:24+00:00 2026-06-12T20:14:24+00:00

I have some code that does not seem to operate the way it should.

  • 0

I have some code that does not seem to operate the way it should. The whole point is to take a 256x128x256x2 array of integers, split it into 256 16x128x16x2 chunks, process the chunks into a byte array, then add that byte array to a main array of bytes to be saved. chunkdata[] is fine before saving, but after saving the whole file is blank except the first 4096 bytes. the location table (location of each chunk in the file) is there and the first four byte “chunk header” is there, everything else is 0’s, which isn’t supposed to happen.

public void createFile(int[][][][] map){
    byte[] file = new byte[fileLength]; //22,024,192 bytes long
    System.arraycopy(Sector.locationTable, 0, file, 0, Sector.locationTable.length); //This works as it should
    for(int cx = 0; cx < 16; cx++)
    {
        for(int cz = 0; cz < 16; cz++)
        {
            int start = sectorLength+cx*(sectorLength*chunkSectorLength)+cz*(chunkRows*sectorLength*chunkSectorLength); //this algorithm works, just rather hideous 
            int[][][][] chunk = getChunk(map, cx * 16, cz * 16); //This works as it should
            byte[] chunkdata = putChunk(chunk); //The data from this is correct

            int counter = 0;
            for(int i=start;i<chunkdata.length;i++){
                file[i]=chunkdata[counter]; //Data loss here?
                counter++;
            }
        }
    }
    System.out.println("Saving file...");
    writeFile(file, fileLocation);
}

public static void writeFile(byte[] file,String filename){
    try{
        FileOutputStream fos = new FileOutputStream(filename);
        fos.write(file);
        fos.close();
        Messages.showSuccessfulSave();
    }catch(Exception ex){
        Messages.showFileSavingError(ex);
    }
}

So, assuming putChunk and getChunk work as intended, and my hideous algorithms, what could cause everything past the first 4096 bytes to be blank?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:14:26+00:00Added an answer on June 12, 2026 at 8:14 pm

    Why are you comparing i against chunkdata.length when i is initialized with start? I think counter should be used instead.

    Current:

       int counter = 0;
       for(int i=start;i<chunkdata.length;i++){
          file[i]=chunkdata[counter]; //Data loss here?
          counter++;
       }
    

    Instead, you want to write something like this:

       int counter = 0;
       for(int i=start;counter<chunkdata.length;i++){
           file[i]=chunkdata[counter]; //Data loss here?
           counter++;
       }
    

    or more compact way:

       for(int i=start,counter = 0;counter<chunkdata.length;i++,counter++){
           file[i]=chunkdata[counter]; //Data loss here?
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have some code that does not seem to be working. This is
Does anyone have some code that will take a TimeZoneInfo field from .NET and
I have some code that does MemoryStream ms = new MemoryStream(); ... return Image.FromStream(ms);
I have some code that does custom drawing. Basically it is form fill program
We have been given some code that does a URLRequest call which is really
I have some code that does (independent) operations on a bunch of Python Imaging
I have some code that will change the background color of a specific label
I have some code that is supposed to return an NSString. Instead it is
I have some code that generates Visio masters for me, and some masters have
I have some code that causes the box2d physics simulation to stutter forever after

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.