Page 1 of 1

After mpd_run_delete no valid status

Posted: February 24th, 2019, 10:54 pm
by StefWe
Hello everybody,

i delete an entry from the queue with the command mpd_run_delete().
My mpd client crashes as soon as i check any status (e.g. mpd_status_get_volume, mpd_status_get_state).
mpd_status_get_volume returns -1, which I can't explain. Because before mpd_run_delete he read the volume back correctly.

If I call any command(e.g. mpd_run_set_volume, mpd_run_play) before I check the status, everything works.

I am very grateful for any help.

Re: After mpd_run_delete no valid status

Posted: February 25th, 2019, 9:34 am
by max
Can't help without more information. What does the crash look like? What does a minimal version of your crashing code look like? Which versions?

Re: After mpd_run_delete no valid status

Posted: February 25th, 2019, 10:21 am
by StefWe
Sorry for the bad description. This is all new to me and I'm trying to describe it better.
I don't have the server version to hand. The client has the version 2.0.9
My code can be found on https://gitlab.com/StefWe/uMPD

As soon as i'm back on my computer i post a minmal version of my crashing code.
The crash looks like my ui based on qml is crashing, because the status update don't work.

I wanted to ask if I might make a mistake and after the command mpd_run_delete something still has to be done. Since there is no crash if I first send a run command and then check the status.

Re: After mpd_run_delete no valid status

Posted: February 25th, 2019, 10:43 am
by max
Version 2.0.9 of what? libmpdclient? No such version exists. Do you mean version 2.9? I hope not, because that version is more than 5 years old.

Re: After mpd_run_delete no valid status

Posted: February 25th, 2019, 11:32 am
by StefWe
Sorry for the wrong information.

I talked about the libmpdclient version. You are totaly right, it is version 2.9 And yes i'm using this version, because it is the version shipped by default with xenial. https://packages.ubuntu.com/xenial/libmpdclient-dev

Re: After mpd_run_delete no valid status

Posted: February 26th, 2019, 11:56 am
by StefWe
I continued to search for my error and found it when I queried the playlist.

My old code:

Code: Select all

QStringList PlayerState::loadPlayList(void) {
 
  QStringList playList;
  struct mpd_status *stat = mpd_run_status(m_connection);
  unsigned queue_length = mpd_status_get_queue_length(stat);
  
  //Prüfen ob es Einträge in der Wiedergabeliste gibt
  if(queue_length > 0 )
  {
    qDebug() << "Abfrage der Wiedergabeliste";
    mpd_send_list_queue_meta(m_connection);
  
    struct mpd_entity *entity;
    const struct mpd_song *song;

    for (unsigned i=0; i < queue_length; i++) {
    
      entity = mpd_recv_entity(m_connection);
      song = mpd_entity_get_song(entity);
      //playList << QString::number(mpd_song_get_id(song));
      playList << mpd_song_get_uri(song);

    }
  }
  else {
    qDebug() << "kein Eintrag in der Wiedergabeliste";
  }
  
  return playList;
}
The new one:

Code: Select all

QStringList PlayerState::loadPlayList(void) {
 
  qDebug() << "Abfrage der Wiedergabeliste";
  
  QStringList playList;
  struct mpd_entity *entity;
  const struct mpd_song *song;
  
  mpd_send_list_queue_meta(m_connection);

  while (entity = mpd_recv_entity(m_connection)) {
      
    if (mpd_entity_get_type(entity) == MPD_ENTITY_TYPE_SONG)
    {
      song = mpd_entity_get_song(entity);
      playList << mpd_song_get_uri(song);
    }
      
    mpd_entity_free(entity);
      
  }
  
  return playList;
}
Now it is working like expected. I can read the status after reading the actual queue.

Many thanks for the quick help and patience.

Re: After mpd_run_delete no valid status

Posted: February 26th, 2019, 6:19 pm
by max
There are two memory leaks in your old code and one memory leak in the new code. In both versions, the call to mpd_response_finish() is missing, leaving the connection in an invalid state. And going back to your initial problem: neither version has a mpd_run_delete() call. I'm confused.

Re: After mpd_run_delete no valid status

Posted: February 27th, 2019, 9:33 pm
by StefWe
max wrote:
February 26th, 2019, 6:19 pm
And going back to your initial problem: neither version has a mpd_run_delete() call. I'm confused.
Sorry for all the confusion. I added the function mpd_run_delete() last. After that I had the problem that my application crashed. This made me suspect that I was doing something wrong with the function call.

But by further debugging I came to the conclusion that querying the playlist is my problem. Therefore now also the code fragments that don't contain mpd_run_delete().

Can I read somewhere in the documentation for which function I have to react with mpd_response_finish() to avoid leaving the connection in an invalid state?

Code: Select all

QStringList PlayerState::loadPlayList(void) {
 
  qDebug() << "Abfrage der Wiedergabeliste";
  onQueueChanged = true;
  
  QStringList playList;
  struct mpd_entity *entity;
  const struct mpd_song *song;
  
  mpd_send_list_queue_meta(m_connection);

  while (entity = mpd_recv_entity(m_connection)) {
      
    if (mpd_entity_get_type(entity) == MPD_ENTITY_TYPE_SONG)
    {
      song = mpd_entity_get_song(entity);
      playList << mpd_song_get_uri(song);
    }
      
    mpd_entity_free(entity);
      
  }
  
  if( !mpd_response_finish(m_connection)) qDebug() << "error on response"
  
  return playList;
}
Is it ok to run the the mpd_response_finish() at the end?

Re: After mpd_run_delete no valid status

Posted: February 27th, 2019, 9:44 pm
by max
You're still talking about the crash without describing the crash. That was my very first question, but you keep ignoring it.

Re: After mpd_run_delete no valid status

Posted: February 27th, 2019, 10:09 pm
by StefWe
I didn't mean to ignore your question. I tried to explain that there is no crash anymore since I changed the playlist query as described above.
It was a false assumption that mpd_run_delete() had something to do with it.