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

ContentWriter bugged... #6661

Open
sharkist opened this issue Feb 13, 2019 · 5 comments
Open

ContentWriter bugged... #6661

sharkist opened this issue Feb 13, 2019 · 5 comments
Labels
ContentPipeline Content processing issues Good First Issue Issues recommended for first-time contributors

Comments

@sharkist
Copy link

whenever I get the "ContentWriter.BaseStream" pointer, then the ContentWriter adding again and again the header in the file. Why ContentWrite write something in the file, i only get basestream.position?

If i do something like below:


        protected override void Write(ContentWriter cs_writer, TilesetContentData tsdata)
        {
            long a = cs_writer.BaseStream.Position;
            long b = cs_writer.BaseStream.Position;
            long c = cs_writer.BaseStream.Position;
            long d = cs_writer.BaseStream.Position;
            long e = cs_writer.BaseStream.Position;
            long f = cs_writer.BaseStream.Position;
            long g = cs_writer.BaseStream.Position;
        };

My file will have "8" XNB header files.

my workaround if i need 'basestream.position' just make first MemoryStream, and later everything copy by Write(memstream.ToArray());

http://oi65.tinypic.com/2gx1eer.jpg

What version of MonoGame does the bug occur on:

  • MonoGame 3.7

What operating system are you using:

  • Windows

What MonoGame platform are you using:

  • DesktopGL
@Jjagg Jjagg added the ContentPipeline Content processing issues label Feb 17, 2019
@Jjagg
Copy link
Contributor

Jjagg commented Feb 17, 2019

ContentWriter writes stuff when its Flush method is called. This is not correct behavior. Flush should not do the actual writing.

@Jjagg Jjagg added the Good First Issue Issues recommended for first-time contributors label Jul 31, 2020
@h3allen
Copy link
Contributor

h3allen commented Mar 19, 2024

Hi! I'm a first time contributor and I'd like to take a stab at fixing this if it's still a problem!

@mrhelmut
Copy link
Contributor

I don't think this issue is still relevant. This behavior is inherited from BinaryWriter and doesn't seem to be a MonoGame issue. This should be tested against .NET 8 to be sure.

@Jjagg
Copy link
Contributor

Jjagg commented Mar 20, 2024

That doesn't sound right @mrhelmut. The Flush implementation should complete buffered write operations, but ContentWriter actually writes new data to the underlying stream.
You can see from the doc comment that the implementation has a wrong perception of what Flush should do:

/// All content has been written, so now finalize the header, footer and anything else that needs finalizing.

Compare with BinaryWriter.Flush's docs and implementation:

        // Clears all buffers for this writer and causes any buffered data to be
        // written to the underlying device.
        public virtual void Flush()
        {
            OutStream.Flush();
        }

The thing to figure out here is when we do need to write the stuff we now write in Flush.

@h3allen
Copy link
Contributor

h3allen commented Mar 20, 2024

From the sounds of it, and from what I've seen, the current Flush call is working to finalize the file after the main body of content has been written, instead of only writing out the remaining data in the buffer. It seems as though this can either be slotted elsewhere in the ContentWriter class where it makes more sense or contained in its own method. What would be best given the current architecture?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ContentPipeline Content processing issues Good First Issue Issues recommended for first-time contributors
Projects
None yet
Development

No branches or pull requests

4 participants