Re: [LAD] Segfault when trying to dereference __midi_event.buffer (c++ newbie question)

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Shani Hadiyanto Pribadi <shanipribadi@...>
Cc: <linux-audio-dev@...>
Date: Wednesday, November 21, 2012 - 12:14 pm

--e89a8f838e49b7e74304cf004af0
Content-Type: text/plain; charset=ISO-8859-1

On Wed, Nov 21, 2012 at 11:54 AM, Shani Hadiyanto Pribadi <
shanipribadi@gmx.net> wrote:

> jack_midi_event_get(&in_event, midi_buf, event_index);

Extra context from you git repo:
void *midi_buf;
jack_midi_event_t in_event;
jack_nframes_t event_index = 0;
jack_nframes_t event_count;

midi_buf = jack_port_get_buffer(_ports[MIDI], nframes);
event_count = jack_midi_get_event_count(midi_buf);

jack_midi_event_get(&in_event, midi_buf, event_index); // error here?
std::cout << std::hex << static_cast (*(in_event.buffer))
<< std::endl;
if (event_count)
{
}

What happens when event_index has a value of 0? It will attempt a read &
dereference anyway.
Perhaps put the jack_midi_event_get() call into the if statement.

Also, you should probably use this instead of if(event_count)

int event_num = 0;
while ( event_num < event_count )
{
// do stuff
event_num++;
}

Haven't tried the above code, but I think that might be it :)
HTH, -Harry

--e89a8f838e49b7e74304cf004af0
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On Wed, Nov 21, 2012 at 11:54 AM, Shani Hadiyant=
o Pribadi <shanipribadi@gmx.net> wrote:
jack_midi_event_get(&in_event, midi_buf, event_index);if ((*(in_eve=
nt.buffer) & 0xf0) =3D=3D 0x90) // Segfault happens here, on boolean ma=
sk operation{=A0=A0=A0 _note =3D *(in_event.buffer + 1);}
Extra context from you git repo:=A0=A0=A0 void *midi_buf;
=A0=A0=A0=A0jack_midi_event_t in=
_event;=A0=A0=A0=A0jack_nframes_t ev=
ent_index =3D 0;
=A0=A0=A0=A0jack_nframes=
_t event_count;=A0=A0=A0=A0midi_buf =3D jack_port_get_buffer(=
_ports[=
MIDI], nframes);
=A0=A0=A0=A0event_count<=
/span> =3D jack_midi_get_event_c=
ount(midi_buf);
=A0=A0=A0=A0jack_midi_event_get(&in_event, <=
span class=3D"n">midi_buf, event_index); // error here?
=A0=A0=A0=A0std::cout << std::=
hex << static_cast<unsigned int> (*(=
in_event.buffer)) <&lt=
; std::endl;
=A0=A0=A0=A0if (event_count)=A0=A0=A0=A0{=A0=A0=A0 }
What happens when event_index has a value of 0? It will attempt =
a read & dereference anyway.Perhaps put the jack_midi_event_get() c=
all into the if=A0 statement.Also, you should probably use this ins=
tead of if(event_count)
int event_num =3D 0;while ( event_num < event_count ){=
=A0=A0 // do stuff=A0=A0 event_num++;}Haven't tried the=
above code, but I think that might be it :)HTH, -Harry=A0

--e89a8f838e49b7e74304cf004af0--

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[LAD] Segfault when trying to dereference __midi_event.buffe..., Shani Hadiyanto Pribadi, (Wed Nov 21, 11:54 am)
Re: [LAD] Segfault when trying to dereference __midi_event.b..., Shani Hadiyanto Pribadi, (Wed Nov 21, 12:49 pm)
Re: [LAD] Segfault when trying to dereference __midi_event.b..., Harry van Haaren, (Wed Nov 21, 12:14 pm)