Results 1 to 6 of 6

Thread: QMediaPlayer crash

  1. #1
    Join Date
    Sep 2019
    Posts
    16
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Question QMediaPlayer crash

    Hello !
    so i have this function in a class that plays an audio file and stops it if it's being active.

    This is the class and its function :
    Qt Code:
    1. #include "soundeffects.h"
    2. #include <QMediaPlayer>
    3. #include <QMediaPlaylist>
    4.  
    5. // klas sound effectov sm naredu in potem jih sam klicm ko jih rabm na primer ko pritisnem SPACE se zazene
    6. // canonBallShot funkcija in sound effect ki se nahaj v tej funkciji;
    7.  
    8. SoundEffects::SoundEffects(){
    9. soundEffect = new QMediaPlayer;
    10. }
    11.  
    12. void SoundEffects::playPlaneEngineSound(){
    13.  
    14. soundEffect->setMedia(QUrl("qrc:/Story_Sounds/PlaneEngine.wav"));
    15.  
    16. if(soundEffect->state() == QMediaPlayer::PlayingState){
    17. soundEffect->stop();
    18. }else if(soundEffect->state() == QMediaPlayer::StoppedState){
    19. soundEffect->play();
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 

    I call the function in game.cpp 3 times like this:
    Qt Code:
    1. soundEffects->playPlaneEngineSound();
    2. soundEffects->playPlaneEngineSound();
    3. SoundEffects->playPlaneEngineSound();
    To copy to clipboard, switch view to plain text mode 
    and the application crashes and i don't know why...
    Could it be because i set media again when the function is called the third time ?
    And if how do i fix it so that when i call the function once, it plays the sound, second time it stops it and so on ( checking if it's active or not and depending on the output the audio is played or stopped ).

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,553
    Thanks
    13
    Thanked 1,580 Times in 1,509 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QMediaPlayer crash

    Quote Originally Posted by FlyDoodle View Post
    and the application crashes and i don't know why...
    Could it be because i set media again when the function is called the third time ?
    And if how do i fix it so that when i call the function once, it plays the sound, second time it stops it and so on ( checking if it's active or not and depending on the output the audio is played or stopped ).
    We can only guess given the information supplied. My guess is that your soundEffects pointer becomes invalid after the second use.

    The error message and the stack backtrace would be useful.
    Last edited by ChrisW67; 6th October 2019 at 09:30.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

  3. #3
    Join Date
    Sep 2019
    Posts
    16
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QMediaPlayer crash

    The error message and the stack backtrace would be useful.
    Here you go:
    mem_fault.PNG
    And
    mem_fault2.jpg

    It's a segmentation fault which means that im trying to access something that doesn't exist ?
    It crashes when the function is called the second time
    Last edited by FlyDoodle; 6th October 2019 at 13:49.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,553
    Thanks
    13
    Thanked 1,580 Times in 1,509 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QMediaPlayer crash

    Ok. So what is m_device set to at the time of the SIGSEGV?

  5. #5
    Join Date
    Sep 2019
    Posts
    16
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QMediaPlayer crash

    Sorry but i don't know how to check that...
    I found this if it helps at all ?
    deb1.jpg

    deb1.jpg

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,553
    Thanks
    13
    Thanked 1,580 Times in 1,509 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QMediaPlayer crash

    Given that the segfault is occurring at that line it is likely that m_device is either nullptr or, I suspect more likely, a value that was previously pointing at a valid object but is no longer.
    In the debugger screenshot at post #3, in the top left, expand "this" and look for "m_device" to see its value. Zero? You can put a breakpoint here to see it on each pass.

    The m_device member variable is set at construction of your DirectShowIOReader, and is valid for some period after that if it only fails on the second pass through readyRead(). The ownership and lifespan of the QIODevice object passed in needs to be considered... does it get deleted or go out of scope?

    Another complication may be the use of threads here.

Similar Threads

  1. Replies: 0
    Last Post: 3rd November 2015, 18:58
  2. Timecode in QMediaPlayer
    By mkarol in forum Qt Programming
    Replies: 1
    Last Post: 5th December 2013, 18:50
  3. Playing MP4 and FLV with QMediaPlayer
    By JasonKretzer in forum Newbie
    Replies: 2
    Last Post: 12th September 2013, 22:58
  4. QMediaPlayer Questions
    By morpheus in forum Newbie
    Replies: 1
    Last Post: 25th August 2013, 15:03
  5. QMediaPlayer problems
    By alenn.masic in forum Qt Programming
    Replies: 1
    Last Post: 25th February 2013, 16:32

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.