timheuer / taglib-sharp-portable

.NET Portable Class Library implementation of TagLib# (forked from TagLib# main project)
Other
58 stars 33 forks source link

Stackoverflow Exception When Saving #5

Closed mattiascibien closed 8 years ago

mattiascibien commented 10 years ago

Hello, I am currently writing a Windows Store (and Phone 8.1) app using your Taglib-Sharp fork. I create the File object using:

            var fileStream = await _tagFileService.File.OpenAsync(FileAccessMode.ReadWrite);
            file = TagLib.File.Create(new StreamFileAbstraction(_tagFileService.File.Name, fileStream.AsStream(), fileStream.AsStream()));
            Tags = file.GetTag(TagTypes.Id3v2);

Then i call file.Save() after modifying it and I get a stackoverflow exception.

timheuer commented 10 years ago

Yikes. Can you tell me what _tagFileService represents?

mattiascibien commented 10 years ago

_tagFileService is just a single instance I use with caliburn micro. It only keeps track of the file choosen using the file picker under Win8.1 and WP8.1 . I am investigating this bug using your source code from github and I discovered that the exception happens in:

public void CloseStream(Stream stream)
{
    stream.Dispose();
}

when called from Mode setter. call stack

adamjez commented 10 years ago

Same issue here with windows phone 8.1

StefanFabian commented 10 years ago

I don't have this error with my custom FileAbstraction maybe you should use (Stream).Flush() instead. This is my FileAbstraction class:

    public class FileAbstraction : TagLib.File.IFileAbstraction
    {
        public FileAbstraction(string name, Stream stream)
        {
            this.Name = name;
            this.ReadStream = stream;
            this.WriteStream = stream;
        }

        public void CloseStream(Stream stream)
        {
            stream.Flush();
        }

        public string Name
        {
            get;
            private set;
        }

        public Stream ReadStream
        {
            get;
            private set;
        }

        public Stream WriteStream
        {
            get;
            private set;
        }
    }
behamann commented 10 years ago

i have got this exception too, in the same area, already tried flush(), dispose() and even flushasync(). describing the situation: User pick a mp3 file from file picker, the tags appers in textboxes to the user could edit them, then when the user save changes i pick the same file, edit the tags with the inputs and try to save, in the save line it takes a lot of time and then is throw an exception maybe the stream is not being closed correctly, idk

Edit: i figure out what happen, I was setting a read stream to both read and write streams, so when saving it was crashing, works well now but just i can't find a good way to deal with album art, any one knows?

pvolchek commented 9 years ago

The following code in File.cs may give us some hints.

        public AccessMode Mode {
            get {return (file_stream == null) ?
                AccessMode.Closed : (file_stream.CanWrite) ?
                    AccessMode.Write : AccessMode.Read;}
            set {
                if (Mode == value || (Mode == AccessMode.Write
                    && value == AccessMode.Read))
                    return;

                if (file_stream != null)
                    file_abstraction.CloseStream (file_stream);

                file_stream = null;

                if (value == AccessMode.Read)
                    file_stream = file_abstraction.ReadStream;
                else if (value == AccessMode.Write)
                    file_stream = file_abstraction.WriteStream;

                Mode = value;
            }
        }

First of all, note that last line is a recursive call, which is causing Process is terminated due to StackOverflowException exception under certain scenarios.

Also notice the call to close the stream. So, if you implement Close() on a stream in your abstraction, then you'll probably end up with System.ObjectDisposedException: Cannot access a closed file.

MrCSharp22 commented 8 years ago

Any updates on how to resolve this issue? Currently have the same problem in my WinRT app.

MrCSharp22 commented 8 years ago

Managed to fix the issue, would like to push the fix to the repo but VS gives me HTTP Error 403 (Forbidden).

mattiascibien commented 8 years ago

@RafaelYousuf you first need to fork the repo and then do the modifications in your fork.

After that you must create a pull request to be reviewed by the original author.

Have a nice day.

MrCSharp22 commented 8 years ago

@mattiascibien thnx for the instructions. I pushed the changes to the repo.

mattiascibien commented 8 years ago

@RafaelYousuf Nice work... :+1:

MrCSharp22 commented 8 years ago

@mattiascibien thank you.