From fc77ae0738565770abde1a25f650a035cf082af0 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 19 Jan 2013 07:00:43 +0000 Subject: Replace a bunch of potential crashes with graceful handling of the situation. We really need some kind of more sophisticated assert macro that can be switched to non-fatal logging mode for release builds. A log message, which is often all that would happen, is a lot better than a trainwrecked performance... git-svn-id: svn://localhost/ardour2/branches/3.0@13892 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/midi_diskstream.cc | 43 +++++++++------------------------- libs/ardour/midi_port.cc | 4 ---- libs/ardour/midi_ring_buffer.cc | 2 -- libs/ardour/midi_stretch.cc | 11 +++++---- libs/evoral/evoral/EventRingBuffer.hpp | 2 +- 5 files changed, 18 insertions(+), 44 deletions(-) (limited to 'libs') diff --git a/libs/ardour/midi_diskstream.cc b/libs/ardour/midi_diskstream.cc index eb4aed91c6..63d70f707c 100644 --- a/libs/ardour/midi_diskstream.cc +++ b/libs/ardour/midi_diskstream.cc @@ -83,7 +83,9 @@ MidiDiskstream::MidiDiskstream (Session &sess, const string &name, Diskstream::F in_set_state = false; - assert(!destructive()); + if (destructive()) { + throw failed_constructor(); + } } MidiDiskstream::MidiDiskstream (Session& sess, const XMLNode& node) @@ -125,8 +127,6 @@ MidiDiskstream::init () _capture_buf = new MidiRingBuffer(size); _n_channels = ChanCount(DataType::MIDI, 1); - - assert(recordable()); } MidiDiskstream::~MidiDiskstream () @@ -222,9 +222,9 @@ MidiDiskstream::find_and_use_playlist (const string& name) int MidiDiskstream::use_playlist (boost::shared_ptr playlist) { - assert(boost::dynamic_pointer_cast(playlist)); - - Diskstream::use_playlist(playlist); + if (boost::dynamic_pointer_cast(playlist)) { + Diskstream::use_playlist(playlist); + } return 0; } @@ -258,8 +258,6 @@ MidiDiskstream::use_new_playlist () int MidiDiskstream::use_copy_playlist () { - assert(midi_playlist()); - if (destructive()) { return 0; } @@ -286,10 +284,7 @@ MidiDiskstream::use_copy_playlist () int MidiDiskstream::set_destructive (bool yn) { - yn = 0; // stop pedantic gcc complaints about unused parameter - assert( ! destructive()); - assert( ! yn); - return -1; + return yn ? -1 : 0; } void @@ -356,7 +351,6 @@ MidiDiskstream::process (framepos_t transport_frame, pframes_t nframes, framecnt MidiBuffer& buf = sp->get_midi_buffer(nframes); for (MidiBuffer::iterator i = buf.begin(); i != buf.end(); ++i) { const Evoral::MIDIEvent ev(*i, false); - assert(ev.buffer()); #ifndef NDEBUG if (DEBUG::MidiIO & PBD::debug_bits) { const uint8_t* __data = ev.buffer(); @@ -667,12 +661,11 @@ MidiDiskstream::do_refill () return 0; } - // At this point we... - assert(_playback_buf->write_space() > 0); // ... have something to write to, and - assert(file_frame <= max_framepos); // ... something to write + /* no space to write */ + if (_playback_buf->write_space() == 0) { + return 0; + } - // now calculate how much time is in the ringbuffer. - // and lets write as much as we need to get this to be midi_readahead; uint32_t frames_read = g_atomic_int_get(&_frames_read_from_ringbuffer); uint32_t frames_written = g_atomic_int_get(&_frames_written_to_ringbuffer); if ((frames_written - frames_read) >= midi_readahead) { @@ -714,8 +707,6 @@ MidiDiskstream::do_flush (RunContext /*context*/, bool force_flush) return 0; } - assert (!destructive()); - total = _session.transport_frame() - _write_source->last_write_end(); if (total == 0 || @@ -805,8 +796,6 @@ MidiDiskstream::transport_stopped_wallclock (struct tm& /*when*/, time_t /*twhen } else { - assert(_write_source); - framecnt_t total_capture = 0; for (ci = capture_info.begin(); ci != capture_info.end(); ++ci) { total_capture += (*ci)->frames; @@ -993,9 +982,6 @@ MidiDiskstream::finish_capture () return; } - // Why must we destroy? - assert(!destructive()); - CaptureInfo* ci = new CaptureInfo; ci->start = capture_start_frame; @@ -1023,8 +1009,6 @@ MidiDiskstream::set_record_enabled (bool yn) return; } - assert(!destructive()); - /* yes, i know that this not proof against race conditions, but its good enough. i think. */ @@ -1116,8 +1100,6 @@ MidiDiskstream::set_state (const XMLNode& node, int version) in_set_state = true; for (niter = nlist.begin(); niter != nlist.end(); ++niter) { - assert ((*niter)->name() != IO::state_node_name); - if ((*niter)->name() == X_("CapturingSources")) { capture_pending_node = *niter; } @@ -1159,8 +1141,6 @@ MidiDiskstream::use_new_write_source (uint32_t n) return 1; } - assert(n == 0); - _write_source.reset(); try { @@ -1293,7 +1273,6 @@ void MidiDiskstream::get_playback (MidiBuffer& dst, framecnt_t nframes) { dst.clear(); - assert(dst.size() == 0); Location* loc = loop_location; diff --git a/libs/ardour/midi_port.cc b/libs/ardour/midi_port.cc index 0856666159..cc72eabba4 100644 --- a/libs/ardour/midi_port.cc +++ b/libs/ardour/midi_port.cc @@ -47,8 +47,6 @@ MidiPort::cycle_start (pframes_t nframes) _buffer->clear (); - assert (_buffer->size () == 0); - if (sends_output ()) { jack_midi_clear_buffer (jack_port_get_buffer (_jack_port, nframes)); } @@ -68,8 +66,6 @@ MidiPort::get_midi_buffer (pframes_t nframes) void* jack_buffer = jack_port_get_buffer (_jack_port, nframes); const pframes_t event_count = jack_midi_get_event_count (jack_buffer); - assert (event_count < _buffer->capacity()); - /* suck all relevant MIDI events from the JACK MIDI port buffer into our MidiBuffer */ diff --git a/libs/ardour/midi_ring_buffer.cc b/libs/ardour/midi_ring_buffer.cc index 0f08247cb9..21f840af10 100644 --- a/libs/ardour/midi_ring_buffer.cc +++ b/libs/ardour/midi_ring_buffer.cc @@ -43,7 +43,6 @@ MidiRingBuffer::read(MidiBuffer& dst, framepos_t start, framepos_t end, frame } T ev_time; - Evoral::EventType ev_type; uint32_t ev_size; size_t count = 0; const size_t prefix_size = sizeof(T) + sizeof(Evoral::EventType) + sizeof(uint32_t); @@ -58,7 +57,6 @@ MidiRingBuffer::read(MidiBuffer& dst, framepos_t start, framepos_t end, frame assert (this->peek (peekbuf, prefix_size)); ev_time = *((T*) peekbuf); - ev_type = *((Evoral::EventType*)(peekbuf + sizeof (T))); ev_size = *((uint32_t*)(peekbuf + sizeof(T) + sizeof (Evoral::EventType))); if (ev_time >= end) { diff --git a/libs/ardour/midi_stretch.cc b/libs/ardour/midi_stretch.cc index 1794d5ff93..38cab08ace 100644 --- a/libs/ardour/midi_stretch.cc +++ b/libs/ardour/midi_stretch.cc @@ -49,8 +49,9 @@ MidiStretch::run (boost::shared_ptr r, Progress*) char suffix[32]; boost::shared_ptr region = boost::dynamic_pointer_cast(r); - if (!region) + if (!region) { return -1; + } /* the name doesn't need to be super-precise, but allow for 2 fractional digits just to disambiguate close but not identical stretches. @@ -74,16 +75,16 @@ MidiStretch::run (boost::shared_ptr r, Progress*) if (make_new_sources (region, nsrcs, suffix)) return -1; - // FIXME: how to make a whole file region if it isn't? - //assert(region->whole_file()); - boost::shared_ptr src = region->midi_source(0); src->load_model(); boost::shared_ptr old_model = src->model(); boost::shared_ptr new_src = boost::dynamic_pointer_cast(nsrcs[0]); - assert(new_src); + if (!new_src) { + error << _("MIDI stretch created non-MIDI source") << endmsg; + return -1; + } Glib::Threads::Mutex::Lock sl (new_src->mutex ()); diff --git a/libs/evoral/evoral/EventRingBuffer.hpp b/libs/evoral/evoral/EventRingBuffer.hpp index 8fec622243..419f427f33 100644 --- a/libs/evoral/evoral/EventRingBuffer.hpp +++ b/libs/evoral/evoral/EventRingBuffer.hpp @@ -116,7 +116,7 @@ template inline uint32_t EventRingBuffer