19 May '13 - 17:21 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: OS X: BASS_ChannelGetPosition exception  (Read 2897 times)
yps
Posts: 107


« on: 31 May '09 - 21:44 »
Reply with quoteQuote

Hi.

Playing around with my new MacBook, I found a strange issue with BASS_ChannelGetPosition on OS X using Free Pascal. Take a look at the following minimal example:

{$linklib bass}

uses
  SysUtils,
  bass;
 
var
  chan: HSTREAM;
  p: QWORD;

begin
  BASS_Init(1, 44100, 0, 0, nil);
  chan := BASS_StreamCreateFile(false, PChar('test.mp3'), 0, 0, BASS_SAMPLE_FLOAT);
  BASS_ChannelPlay(chan, false);
  readln;
  p := BASS_ChannelGetPosition(chan, BASS_POS_BYTE);
  Writeln(IntToStr(p));
  readln;
end.

This code works fine. However, when I omit the first "readln" and query the current position directly after the call to BASS_ChannelPlay, there's an invalid floating point exception inside BASS_ChannelGetPosition, obviously caused by a nested call to BASS_ChannelIsSliding:

Program received signal EXC_ARITHMETIC, Arithmetic exception.
0x00087770 in BASS_ChannelIsSliding ()
(gdb) bt
#0  0x00087770 in BASS_ChannelIsSliding ()
#1  0x00000000 in ?? ()

Remember, this only happens when you query the position right after the beginning of the playback. At any later point, it's ok.

The code is compiled with fpc in Delphi mode (-Mdelphi) using the bass.pas file from the BASS for Linux distribution (because of the calling conventions). BASS_ChannelGetPosition is declared as cdecl, I guess this is correct for OS X. The libbass.dylib is the one from the current release, downloaded from un4seen just yesterday.

Interestingly, when I rewrite the example code in C and compile it with gcc on the same machine, it works just fine.

Does anybody have a clue what's going on here?


Torben
Logged
Ian @ un4seen
Administrator
Posts: 15244


« Reply #1 on: 1 Jun '09 - 15:39 »
Reply with quoteQuote

This code works fine. However, when I omit the first "readln" and query the current position directly after the call to BASS_ChannelPlay, there's an invalid floating point exception inside BASS_ChannelGetPosition, obviously caused by a nested call to BASS_ChannelIsSliding:

Program received signal EXC_ARITHMETIC, Arithmetic exception.
0x00087770 in BASS_ChannelIsSliding ()
(gdb) bt
#0  0x00087770 in BASS_ChannelIsSliding ()
#1  0x00000000 in ?? ()

Remember, this only happens when you query the position right after the beginning of the playback. At any later point, it's ok.

I think I see what's causing that. It was possible that there could be a floating-point division by 0 when getting the position before the channel has actually started playing. I guess it's a similar story on OSX as on Windows, in that Delphi/Pascal won't disable floating-point exceptions by default, whereas C/C++ compilers/runtimes will. Here's an update to try, which should avoid the division by 0...

   www.un4seen.com/stuff/libbass.dylib

Btw, the problem wasn't actually in BASS_ChannelIsSliding. There are no symbols included for internal functions, so that's just the preceding symbol that the debugger could find Smiley
Logged
yps
Posts: 107


« Reply #2 on: 1 Jun '09 - 18:24 »
Reply with quoteQuote

Wonderful, works like a charm. Let's see how I get on with the Mac stuff. Perhaps I will have to buy another BASS license soon Wink


Cheers,

Torben
Logged
dloginov
Posts: 9


« Reply #3 on: 19 Jan '10 - 12:41 »
Reply with quoteQuote

Last version BASS(http://www.un4seen.com/download.php?bass24-osx) still crash on exit application (when bass play track):

Quote
Process:         YotaMusic [596]
Path:            /Applications/YotaMusic.app/Contents/MacOS/YotaMusic
Identifier:      com.yota.YotaMusic
Version:         1.5.0.7 (1.5.0.7)
Code Type:       X86 (Native)
Parent Process:  launchd [76]

Date/Time:       2010-01-19 15:09:46.322 +0300
OS Version:      Mac OS X 10.6.2 (10C540)
Report Version:  6

Interval Since Last Report:          63357 sec
Crashes Since Last Report:           1
Per-App Interval Since Last Report:  6147 sec
Per-App Crashes Since Last Report:   1
Anonymous UUID:                      6F117CEB-86FC-4022-887F-089D51FCC245

Exception Type:  EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x000000000000001c
Crashed Thread:  4
...
Thread 4 Crashed:
0   libbass.dylib                    0x02da7306 BASS_ChannelIsSliding + 9070
1   com.apple.audio.CoreAudio        0x960f25b4 HP_IOProc::Call(AudioTimeStamp const&, AudioTimeStamp const&, AudioBufferList const*, AudioTimeStamp const&, AudioBufferList*) + 374
2   com.apple.audio.CoreAudio        0x960f231a IOA_Device::CallIOProcs(AudioTimeStamp const&, AudioTimeStamp const&, AudioTimeStamp const&) + 370
3   com.apple.audio.CoreAudio        0x960f2116 HP_IOThread::PerformIO(AudioTimeStamp const&, double) + 620
4   com.apple.audio.CoreAudio        0x960ef4fa HP_IOThread::WorkLoop() + 2506
5   com.apple.audio.CoreAudio        0x960eeb2b HP_IOThread::ThreadEntry(HP_IOThread*) + 17
6   com.apple.audio.CoreAudio        0x960eea42 CAPThread::Entry(CAPThread*) + 140
7   libSystem.B.dylib                0x94221fbd _pthread_start + 345
8   libSystem.B.dylib                0x94221e42 thread_start + 34

Thread 5:
0   libSystem.B.dylib                0x9421a182 __workq_kernreturn + 10
1   libSystem.B.dylib                0x9421a718 _pthread_wqthread + 941
2   libSystem.B.dylib                0x9421a336 start_wqthread + 30

Thread 4 crashed with X86 Thread State (32-bit):
  eax: 0x02f6f7f0  ebx: 0x02da721d  ecx: 0x00000000  edx: 0xa047f480
  edi: 0x00000004  esi: 0x02fbfbe0  ebp: 0xb03a6af8  esp: 0xb03a6aa0
   ss: 0x0000001f  efl: 0x00010202  eip: 0x02da7306   cs: 0x00000017
   ds: 0x0000001f   es: 0x0000001f   fs: 0x0000001f   gs: 0x00000037
  cr2: 0x0000001c
« Last Edit: 19 Jan '10 - 15:47 by dloginov » Logged
Ian @ un4seen
Administrator
Posts: 15244


« Reply #4 on: 19 Jan '10 - 16:09 »
Reply with quoteQuote

That looks like something different to the original post, eg. EXC_BAD_ACCESS vs EXC_ARITHMETIC. My guess is that the app might not be calling BASS_Free before exiting, or not calling it enough times if there are multiple devices initialized? To free all initialized devices, you can simply do this...

while (BASS_Free()) ; // free all output devices
while (BASS_RecordFree()) ; // free all recording devices

If you still have the problem after doing that, I think I will have to send you a debug version for further info.
Logged
dloginov
Posts: 9


« Reply #5 on: 19 Jan '10 - 16:11 »
Reply with quoteQuote

quote crash code
    BassPlayer::~BassPlayer()
    {
        disconnect();
        m_isBassInited  = false;
        if (m_stream>0)
        {
            BASS_ChannelSetAttribute( m_stream, BASS_ATTRIB_VOL, 0 );
            BASS_ChannelStop( m_stream );
            BASS_StreamFree( m_stream );
        }
        BASS_Stop();
        BASS_Free();
    }
Logged
dloginov
Posts: 9


« Reply #6 on: 19 Jan '10 - 16:29 »
Reply with quoteQuote

Anyway thanks for answer. I try to use your solution + bass version from this topic.
Logged
Ian @ un4seen
Administrator
Posts: 15244


« Reply #7 on: 19 Jan '10 - 16:51 »
Reply with quoteQuote

quote crash code
   BassPlayer::~BassPlayer()
...

How is that being called, eg. are you calling "delete" or is it left to the compiler? Does your code look like this...

BassPlayer *player;

...

player = new BassPlayer;

...

delete player;

Or this...

BassPlayer player;

If the latter, please try the former.
Logged
dloginov
Posts: 9


« Reply #8 on: 19 Jan '10 - 16:59 »
Reply with quoteQuote

//...
class PLAYER_MACHINE_API PlayerMachine: public IPlayerMachine
{
///...
private:
    BassPlayer m_player;
}

//...
player_machine::IPlayerMachinePtr player_machine::IPlayerMachine::createPlayerMachine()
{
    return IPlayerMachinePtr(new PlayerMachine());

}
//...
////////////////////////////////////////////////////////////////////////////////
class Player : public IPlayer
{
//...
    /// Player machine implementation.
    IPlayerMachinePtr m_playerMachine;
}

//...
Player::Player(const IServiceGatewayPtr& sgw)
    : m_state(psStopped)
    , m_playType(ptQueue)
    , m_repeat(false)
    , m_serviceGw(sgw)
    ,m_totalSize(0)
    ,m_loadedSize(0)
{
// Seed the random-number generator with the current time so that
// the numbers will be different every time we run.
srand( (unsigned)time( NULL ) );

    m_playerMachine.reset(new PlayerMachineUrlResolver(player_machine::IPlayerMachine::createPlayerMachine(), m_serviceGw));

IPlayerMachinePtr is a boost::shared_ptr
Logged
Ian @ un4seen
Administrator
Posts: 15244


« Reply #9 on: 19 Jan '10 - 17:09 »
Reply with quoteQuote

OK, I will send you a debug version to get some further info.
Logged
Graff
Posts: 1


« Reply #10 on: 3 Jun '10 - 13:14 »
Reply with quoteQuote

Having the same issue as dloginov with latest version of bass
it crashes after the program exits.
here is report.
where is the problem?

Process:         XXXXX
Path:            /Applications/XXXXXX
Identifier:      com.XXXXXXX
Version:         ??? (1.0)
Code Type:       X86 (Native)
Parent Process:  launchd [81]

Interval Since Last Report:          86280 sec
Crashes Since Last Report:           9
Per-App Interval Since Last Report:  6330 sec
Per-App Crashes Since Last Report:   2

Date/Time:       2010-06-03 11:16:54.392 +0400
OS Version:      Mac OS X 10.5.8 (9L31a)
Report Version:  6
Anonymous UUID:  D0FD74FE-7AF8-4159-9CA2-900821AA41ED

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000000cd71219b
Crashed Thread:  3

------

Thread 1:
0   libSystem.B.dylib              0x95a5e266 mach_msg_trap + 10
1   libSystem.B.dylib              0x95a65a5c mach_msg + 72
2   com.apple.CoreFoundation      0x96d78e7e CFRunLoopRunSpecific + 1790
3   com.apple.CoreFoundation      0x96d79aa8 CFRunLoopRunInMode + 88
4   com.apple.audio.CoreAudio      0x9334e5f8 HALRunLoop::OwnThread(void*) + 160
5   com.apple.audio.CoreAudio      0x9334e480 CAPThread::Entry(CAPThread*) + 96
6   libSystem.B.dylib              0x95a8f155 _pthread_start + 321
7   libSystem.B.dylib              0x95a8f012 thread_start + 34

Thread 2:
0   libSystem.B.dylib              0x95a6544e __semwait_signal + 10
1   libSystem.B.dylib              0x95a8fdcd pthread_cond_wait$UNIX2003 + 73
2   libGLProgrammability.dylib    0x95d0cb32 glvmDoWork + 162
3   libSystem.B.dylib              0x95a8f155 _pthread_start + 321
4   libSystem.B.dylib              0x95a8f012 thread_start + 34

Thread 3 Crashed:
0   libbass.dylib                  0x009cb2c4 BASS_ChannelIsSliding + 17060
1   com.apple.audio.CoreAudio      0x93360177 HP_IOProc::Call(AudioTimeStamp const&, AudioTimeStamp const&, AudioBufferList const*, AudioTimeStamp const&, AudioBufferList*) + 319
2   com.apple.audio.CoreAudio      0x9335fe68 IOA_Device::CallIOProcs(AudioTimeStamp const&, AudioTimeStamp const&, AudioTimeStamp const&) + 274
3   com.apple.audio.CoreAudio      0x9335fd44 HP_IOThread::PerformIO(AudioTimeStamp const&) + 1246
4   com.apple.audio.CoreAudio      0x9335e11f HP_IOThread::WorkLoop() + 1239
5   com.apple.audio.CoreAudio      0x9335dc43 HP_IOThread::ThreadEntry(HP_IOThread*) + 17
6   com.apple.audio.CoreAudio      0x9334e480 CAPThread::Entry(CAPThread*) + 96
7   libSystem.B.dylib              0x95a8f155 _pthread_start + 321
8   libSystem.B.dylib              0x95a8f012 thread_start + 34

Thread 3 crashed with X86 Thread State (32-bit):
  eax: 0x19d5b450  ebx: 0x009cb1db  ecx: 0x00000000  edx: 0x00000000
  edi: 0xcd712183  esi: 0x009cb1d0  ebp: 0xb0184b88  esp: 0xb0184b30
   ss: 0x0000001f  efl: 0x00010282  eip: 0x009cb2c4   cs: 0x00000017
   ds: 0x0000001f   es: 0x0000001f   fs: 0x0000001f   gs: 0x00000037
  cr2: 0xcd71219b

----

Logged
Ian @ un4seen
Administrator
Posts: 15244


« Reply #11 on: 3 Jun '10 - 14:54 »
Reply with quoteQuote

If you haven't already done so, please try the "stuff" build...

   www.un4seen.com/stuff/libbass.dylib

If the problem still happens with that, I'll have to send you a debug version to get some further info.
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines