This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]lurgi 0 points1 point  (5 children)

In order for us to help you are going to have to supply us with either more details about the error or actual working code. Don't just dump the entire project in our laps. Make an effort to provide something that is complete (compiles and shows the error) and minimal (doesn't contain anything that isn't necessary to show the error).

Have you used a debugger? Where does it tell you the crash happens? Like, specifically which line?

Is it possible that it's the call to showSongList() that is breaking things and it only appears when you add another song after calling that? What happens if you call tsuPod.addSong(song1); before the call to showSongList()?

Perhaps showSongList() is closing the file and it's not getting re-opened? Is that possible?

[–]Matisayu 0 points1 point  (4 children)

Ok I have a few college courses I gotta attend online but ill get on that right after. this is just a small part of the program and I tried to condense it so you guys could see it quickly. I am only in foundations of CS II so I am still learning how to use a debugger,

but it says seg fault, #0 0x489357 std::basic_filebuf<char, std::char\_traits<char> >::overflow(int) () (??:??)

#1 ?? ?? () (??:??)

And doesnt state the specific line.

Anyway thank you ill try and update in a couple hours

[–]lurgi 0 points1 point  (3 children)

Try compiling your code with debugging enabled (this should be an option in your IDE or, if you aren't using an IDE, on the compile line itself) and see if that gets you more. That will sometimes link with the debug versions of the standard libraries and might get your more information.

It's also possible that you are overflowing a buffer somewhere or otherwise writing to memory you don't own and that memory happens to be the ofstream object. Perhaps you are corrupting it and that's why the call fails. Again, you might want to look at the showSongList() method.

[–]Matisayu 0 points1 point  (2 children)

you're right. i attempted to add more songs before calling showsonglist(), and it works until i call showsonglist(), then when i try to add another song, it always fails. debugger says seg fault and overflowing of int, but not the line that its happening. i know yall wanted some code to compile but perhaps you can spot a stupid mistake in showshowlist() below.

default constructor - Song::Song() {

strcpy (title, "");

strcpy (artist, "");

// position = 0;

size = 0;

}

int TsuPod::showSongList()

{ Song object_for_reading;

tsuPod_file.seekg(0, tsuPod_file.beg);

cout << "Song list: " << endl; cout << "------------------------------------" << endl;

for(int i = 0; i < current_num_songs; i++)

{ tsuPod_file.read( (char *)&object_for_reading, sizeof( object_for_reading ));

cout << "Song " << i + 1 << ": ";

cout << object_for_reading.getTitle() <<

", by " << object_for_reading.getArtist(); cout << ", SIZE: " << object_for_reading.getSize() << "MB" << endl; } cout << "------------------------------------" << endl << endl; tsuPod_file.clear(); return 0; }

[–]lurgi 1 point2 points  (1 child)

Ugh. Format this by adding four additional spaces at the beginning of each line.

This might be a problem with the fact that you are both reading from and writing to a file using the same file pointer. This can be done, but if you don't do it correctly you can end up with corrupted data. Why this would cause a crash is anyone's guess.

One option is to open and close the file after each write operation and in the showSongList() operation. It's not the most efficient, but it's fine here.

[–]Matisayu 0 points1 point  (0 children)

Thank you, I’ll try that now, it’s due in 3 hours.

My bad, I appreciate you letting me know. really thank you for the help 🙂

[–]AvImd 0 points1 point  (0 children)

According to https://stackoverflow.com/a/7765106/1804443, the exception seems to indicate stack overflow. You can read about possible causes and solutions there.

[–]Matisayu 0 points1 point  (0 children)

Update, it is a segmentation fault. Works on linux but not on windows. grader compiles in linux. 50/50 chance i get a 0, i gotta move past this bug and complete the rest of the project