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