<div dir="ltr">Hi Gary,<div><br></div><div style>Thanks for looking into this. I thought I was on the latest version, but looks like i&#39;m on 4.4.3 -- perhaps whoever wrapped STK up as a Juce module hasn&#39;t updated it to the latest version. Let me see if I can get 4.4.4 working with Juce. In the meantime, I&#39;m curious to see if Stephen is also on an older version ...</div>
<div style><br></div><div style>nick</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jul 2, 2013 at 10:43 AM, Gary Scavone <span dir="ltr">&lt;<a href="mailto:gary@ccrma.stanford.edu" target="_blank">gary@ccrma.stanford.edu</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Nick and Stephen,<br>
<br>
I didn&#39;t have a problem compiling and running either example using gcc 4.2.1 on OS-X.  Again, did you check to make sure you were using the latest release of STK?<br>
<span class="HOEnZb"><font color="#888888"><br>
--gary<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On 2013-06-19, at 12:43 PM, Stephen Sinclair &lt;<a href="mailto:sinclair@music.mcgill.ca">sinclair@music.mcgill.ca</a>&gt; wrote:<br>
<br>
&gt; By the way, I tried compiling STK without the errorString_ member<br>
&gt; variable and then your initial examples worked fine.  I guess the<br>
&gt; lesson is that an ostringstream is not a &quot;value&quot; and can&#39;t be copied,<br>
&gt; so shouldn&#39;t be used to contain data, but only to construct it.<br>
&gt;<br>
&gt; On Wed, Jun 19, 2013 at 6:03 PM, Nick Dika &lt;<a href="mailto:nhdika@gmail.com">nhdika@gmail.com</a>&gt; wrote:<br>
&gt;&gt; Thanks Stephen for your detailed explanation. I realize what I was doing<br>
&gt;&gt; with the array example was sloppy, the goal was really to get it working<br>
&gt;&gt; with Vector and push_back() so that I can scale the container as needed. I<br>
&gt;&gt; will try your suggestion later and see if I&#39;m able to get it working.<br>
&gt;&gt;<br>
&gt;&gt; n<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; On Wed, Jun 19, 2013 at 9:45 AM, Stephen Sinclair &lt;<a href="mailto:sinclair@music.mcgill.ca">sinclair@music.mcgill.ca</a>&gt;<br>
&gt;&gt; wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Hi Nick,<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; On Wed, Jun 19, 2013 at 3:09 PM, Nick Dika &lt;<a href="mailto:nhdika@gmail.com">nhdika@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt;&gt; Thanks Stephen. Here&#39;s a simplified version of what I&#39;m doing.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; This works:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; stk::BlitSaw oscArray[10];<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; for( int i=0; i &lt; 10; i++ )<br>
&gt;&gt;&gt;&gt; {<br>
&gt;&gt;&gt;&gt; stk::BlitSaw saw;<br>
&gt;&gt;&gt;&gt; saw.setHarmonics(0);<br>
&gt;&gt;&gt;&gt; saw.setFrequency(220);<br>
&gt;&gt;&gt;&gt; oscArray[i] = saw;<br>
&gt;&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Actually in g++-4.7 at least, this code does not compile.  The BlitSaw<br>
&gt;&gt;&gt; class is unassignable.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; (I&#39;m not 100% sure why, but it seems to be because objects of class<br>
&gt;&gt;&gt; Stk contain a std::ostringstream member which is unassignable.)<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; This breaks:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; std::vector&lt;stk::BlitSaw&gt; oscs;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; for( int i=0; i &lt; 10; i++ )<br>
&gt;&gt;&gt;&gt; {<br>
&gt;&gt;&gt;&gt; stk::BlitSaw saw;<br>
&gt;&gt;&gt;&gt; saw.setHarmonics(0);<br>
&gt;&gt;&gt;&gt; saw.setFrequency(220);<br>
&gt;&gt;&gt;&gt; oscs.push_back(saw);<br>
&gt;&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; This is effectively equivalent to the above code so I&#39;m not 100% why<br>
&gt;&gt;&gt; it&#39;s breaking things but probably the object is not being properly<br>
&gt;&gt;&gt; copied within the vector.  In particular, since you have a vector of<br>
&gt;&gt;&gt; instances of BlitSaw, when the internal array in the std::vector is<br>
&gt;&gt;&gt; re-allocated, perhaps the new, copied memory is not properly<br>
&gt;&gt;&gt; initialized 100%, since the object type is not assignable.  Just a<br>
&gt;&gt;&gt; guess, but it&#39;s weird behaviour for sure, but due to undefined<br>
&gt;&gt;&gt; behaviour because this isn&#39;t how you should do what you&#39;re trying to<br>
&gt;&gt;&gt; do.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; the second example causes an unhandled exception/access violation<br>
&gt;&gt;&gt;&gt; reading<br>
&gt;&gt;&gt;&gt; from a location. As mentioned this appears to happen after<br>
&gt;&gt;&gt;&gt; StkFrames::resize() is called (I don&#39;t fully understand why this would<br>
&gt;&gt;&gt;&gt; be<br>
&gt;&gt;&gt;&gt; called).<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; All Generators, which BlitSaw is one, have an StkFrame called<br>
&gt;&gt;&gt; lastFrames_, and it&#39;s resize() method is called during initialization.<br>
&gt;&gt;&gt; Not sure why it&#39;s leading to an exception but like your array doesn&#39;t<br>
&gt;&gt;&gt; contain valid BlitSaw instances.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Anyways, to elaborate, the way you&#39;re initializing things isn&#39;t<br>
&gt;&gt;&gt; fundamentally wrong, so it could indicate some bugs somewhere, but<br>
&gt;&gt;&gt; it&#39;s certainly not the ideal way to work with Stk objects.  You are<br>
&gt;&gt;&gt; creating an array of objects, such that their constructors are called,<br>
&gt;&gt;&gt; and then a loop you are constructing a new object on the stack,<br>
&gt;&gt;&gt; setting its parameters, and then copying that object over top of the<br>
&gt;&gt;&gt; objects already in the array and letting it destruct.  Not the most<br>
&gt;&gt;&gt; efficient approach.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; (Note, your push_back() call also doesn&#39;t compile in g++-4.7.)<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Instead I&#39;d suggest either directly initializing the objects that are<br>
&gt;&gt;&gt; already in the array, or initializing them and then storing their<br>
&gt;&gt;&gt; pointers in the array.  i.e., either:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; #include &lt;iostream&gt;<br>
&gt;&gt;&gt; #include &lt;Stk.h&gt;<br>
&gt;&gt;&gt; #include &lt;BlitSaw.h&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; int main()<br>
&gt;&gt;&gt; {<br>
&gt;&gt;&gt;    stk::BlitSaw oscs[10];<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;    for( int i=0; i &lt; 10; i++ )<br>
&gt;&gt;&gt;    {<br>
&gt;&gt;&gt;        stk::BlitSaw *saw = &amp;oscs[i];<br>
&gt;&gt;&gt;        saw-&gt;setHarmonics(0);<br>
&gt;&gt;&gt;        saw-&gt;setFrequency(220);<br>
&gt;&gt;&gt;    }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;    return 0;<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; .. or ..<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; #include &lt;iostream&gt;<br>
&gt;&gt;&gt; #include &lt;memory&gt;<br>
&gt;&gt;&gt; #include &lt;Stk.h&gt;<br>
&gt;&gt;&gt; #include &lt;BlitSaw.h&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; int main()<br>
&gt;&gt;&gt; {<br>
&gt;&gt;&gt;    std::vector&lt;std::unique_ptr&lt;stk::BlitSaw&gt;&gt; oscs;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;    for( int i=0; i &lt; 10; i++ )<br>
&gt;&gt;&gt;    {<br>
&gt;&gt;&gt;        std::unique_ptr&lt;stk::BlitSaw&gt; saw(new stk::BlitSaw);<br>
&gt;&gt;&gt;        saw-&gt;setHarmonics(0);<br>
&gt;&gt;&gt;        saw-&gt;setFrequency(220);<br>
&gt;&gt;&gt;        oscs.push_back(std::move(saw));<br>
&gt;&gt;&gt;    }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;    return 0;<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Steve<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt; Stk mailing list<br>
&gt;&gt;&gt; <a href="mailto:Stk@ccrma.stanford.edu">Stk@ccrma.stanford.edu</a><br>
&gt;&gt;&gt; <a href="http://ccrma-mail.stanford.edu/mailman/listinfo/stk" target="_blank">http://ccrma-mail.stanford.edu/mailman/listinfo/stk</a><br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Stk mailing list<br>
&gt;&gt; <a href="mailto:Stk@ccrma.stanford.edu">Stk@ccrma.stanford.edu</a><br>
&gt;&gt; <a href="http://ccrma-mail.stanford.edu/mailman/listinfo/stk" target="_blank">http://ccrma-mail.stanford.edu/mailman/listinfo/stk</a><br>
&gt;&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Stk mailing list<br>
&gt; <a href="mailto:Stk@ccrma.stanford.edu">Stk@ccrma.stanford.edu</a><br>
&gt; <a href="http://ccrma-mail.stanford.edu/mailman/listinfo/stk" target="_blank">http://ccrma-mail.stanford.edu/mailman/listinfo/stk</a><br>
<br>
</div></div></blockquote></div><br></div>