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

Stackoverflow Exception When Saving #5

Closed
mattiascibien opened this issue Jun 10, 2014 · 12 comments
Closed

Stackoverflow Exception When Saving #5

mattiascibien opened this issue Jun 10, 2014 · 12 comments
Assignees
Labels
Milestone

Comments

@mattiascibien
Copy link

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 timheuer added the bug label Jun 10, 2014
@timheuer timheuer added this to the 1.1 milestone Jun 10, 2014
@timheuer timheuer self-assigned this Jun 10, 2014
@timheuer
Copy link
Owner

Yikes. Can you tell me what _tagFileService represents?

@mattiascibien
Copy link
Author

_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
Copy link

adamjez commented Jul 30, 2014

Same issue here with windows phone 8.1

@StefanFabian
Copy link

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
Copy link

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
Copy link

pvolchek commented Jun 4, 2015

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
Copy link
Contributor

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

@MrCSharp22
Copy link
Contributor

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

@mattiascibien
Copy link
Author

@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 added a commit to MrCSharp22/taglib-sharp-portable that referenced this issue Dec 10, 2015
@MrCSharp22
Copy link
Contributor

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

@ghost ghost mentioned this issue Jan 3, 2016
timheuer added a commit that referenced this issue Jan 7, 2016
@timheuer timheuer closed this as completed Jan 7, 2016
@mattiascibien
Copy link
Author

@RafaelYousuf Nice work... 👍

@MrCSharp22
Copy link
Contributor

@mattiascibien thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants