Skip to content

Fixing crashes, code cleaning, and features! - #34

Draft
CodeforEvolution wants to merge 1 commit into
HaikuArchives:masterfrom
CodeforEvolution:crashEtClean
Draft

Fixing crashes, code cleaning, and features!#34
CodeforEvolution wants to merge 1 commit into
HaikuArchives:masterfrom
CodeforEvolution:crashEtClean

Conversation

@CodeforEvolution

Copy link
Copy Markdown
Contributor

I think I got carried away... :)

Quite a few things:
- Code formatting
- More checks for failing functions and NULL
- We look for B_SIMPLE_DATA (it's the same format as B_REFS_RECEIVED)
- Added automatic size limits to the MainWindow
- Removed unused "Buffering.h" and unused function "MainWindow::SetVisible"

Should fix HaikuArchives#33, HaikuArchives#32, HaikuArchives#29

@humdingerb humdingerb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, commented just for an explanation...

Also, in the future you may want to put all code style changes in its own commit (within the one PR). Makes sorting out the functional changes easier.

Comment thread MainWindow.cpp
= fSettings->Stations->FindItem(station->Name());
if (existingStation) {
if (existingStation != NULL) {
delete station;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for my education:

  • why is object 'station' destroyed via "delete" when it wasn't created with "new"?
  • how can the object 'station' that was 'deleted' in the previous line get a new value assigned?
    I ask genuinely. I really am a crappy 'coder'...

@CodeforEvolution CodeforEvolution Sep 1, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must admit, I need to work on separating my style changes. :)

And hey, no worries! I'm happy to explain:

While it may look like the station variable isn't allocated with "new", you'll want to look above at this line:
Station* station = Station::Load(ref.name, new BEntry(&ref));

We'll want to look in the Station.cpp file and find the function that's being called above:

Station::Load(BString name, BEntry* entry)

We can see that in this function, a Station object is allocated with "new":

Station* station = new Station(name);

Eventually, if all goes well in the Load() function, we are returned the fresh "Station" object that was created by "new":

return station;

As a result, the station variable is assigned to the Station object that was created with "new".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for the immediate reassignment, you'll want to check out this video about pointers:
https://youtu.be/DTxHyVn0ODg

He also makes a bunch of other great videos on C++ too:
https://www.youtube.com/playlist?list=PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanations!
I didn't find anything on "immediate reassignment" in that video. I sat through the 15 minutes of it though and would advise the guy to keep away from the coffee while recording. :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem! On the other hand, you get a lot of info and in a short amount of time! ;)

@CodeforEvolution

Copy link
Copy Markdown
Contributor Author

Hold up...one quick problem that I introduced that needs to be fixed...

@CodeforEvolution
CodeforEvolution marked this pull request as draft September 2, 2020 00:39
@humdingerb

Copy link
Copy Markdown
Member

@CodeforEvolution, ready to be merged? Or, what's the quick problem?

@Vidrep

Vidrep commented Sep 6, 2020

Copy link
Copy Markdown

humdinger, I've been using this brach for a few days now. Not a single crash. Maybe just a couple of tweaks to the GUI are all that's needed now.

@CodeforEvolution

Copy link
Copy Markdown
Contributor Author

Unfortunately this is still not mergeable, even though the program isn’t crashing, without that “delete”, StreamRadio will start leaking network threads and audio resources when switching between stations. I just don’t have the time to look into this further...though I think it might be BLocker related?

@humdingerb

Copy link
Copy Markdown
Member

Can you link to the specific location(s) in the code that's the issue? Not that I can fix it, most probably, but maybe someone else can... :)

Are the leaks that severe that it impacts usage so significantly, that we shouldn't release these PRs improvements?

@CodeforEvolution

Copy link
Copy Markdown
Contributor Author

https://github.com/CodeforEvolution/StreamRadio/blob/029dbd4c1212533b39cbe73c42f79db5507bc448/MainWindow.cpp#L321
Before my changes, the "player" variable was deleted right above this line of code, which deleted an instance of the "StreamPlayer" class (a class that handles playback for a single station). This "delete" was causing a crash for me (and it seems for you guys too) that occurred after playing and pausing any station two times. The crash had to do with BLocker when it was trying to be destructed (which StreamPlayer is based upon). But the problem is pretty simple if we don't use delete: The StreamPlayer is leaked. This is because once the associated "StationItem" instance is unmapped from it, nothing else is keeping track of the StreamPlayer, and thus its resources, including a network thread that was used for reading the audio data, is leaked.

@Vidrep

Vidrep commented Oct 5, 2020

Copy link
Copy Markdown

Playing around with Cppcheck, so decided to run it on MainWindow.cpp. Result below. Hope it helps.

~/HaikuArchives/StreamRadio-crashEtClean> cppcheck --enable=all MainWindow.cpp
Checking MainWindow.cpp ...
[MainWindow.cpp:53]: (style) C-style pointer casting
[StationListView.h:41]: (style) Class 'StationListViewItem' has a constructor with 1 argument that is not explicit.
[StationListView.h:74]: (style) Class 'StationListView' has a constructor with 1 argument that is not explicit.
[StationFinder.h:74]: (style) Class 'FindByCapability' has a constructor with 1 argument that is not explicit.
[StationFinder.h:132]: (style) Class 'StationFinderWindow' has a constructor with 1 argument that is not explicit.
Checking MainWindow.cpp: DEBUGGING...
Checking MainWindow.cpp: PROFILING...
Checking MainWindow.cpp: TRACING...
[MainWindow.cpp:393]: (style) The function 'QuitRequested' is never used.

@jsteinaker

jsteinaker commented Feb 20, 2021

Copy link
Copy Markdown

Sorry about not quoting and stuff. I might have discovered what's happening here (but then again, I don't know jack about C++ so...). On the StreamPlayer class destructor, I've just commented the first line, which posts the MSG_PLAYER_STATE_CHANGED message (Stopped). If you take a look at MainWindow.cpp, when the window receives a message like that triggers the delete routine again, which in turn calls the destructor, which will try to post the message again, thus causing a loop or double-delete

This change (plus the others) is already on PR. Can someone give it a try and confirm if it's working (and correct me if I'm wrong about what I think it's happening)?

@humdingerb

Copy link
Copy Markdown
Member

This change (plus the others) is already on PR. Can someone give it a try and confirm if it's working (and correct me if I'm wrong about what I think it's happening)?

Just to clarify, the PR you ask to try is #39, right? (Pulkomandy and I alredy commented there.)

@humdingerb humdingerb mentioned this pull request Nov 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants