Author |
Message |
moudi
Joined: Oct 07, 2006 Posts: 63 Location: Bern Switzerland
|
Posted: Mon Jan 08, 2007 5:10 pm Post subject:
static arrays |
 |
|
ok, here's the second one as mentioned in the thread before...
i tried to use a static array in one of my public classes.
everytime i tried to write to it, my miniAudicle crashed
here's also a little example...
Code: |
public class crash
{
0 => static int myint;
[0,1,2] @=> static int myarray[];
}
//Chuck Values to this Variables without instanciation.
//The pure integer works:
1 => crash.myint;
//This one crashs miniAudicle!!:
10 => crash.myarray[1];
//I assume it's because an array is an object and needs
//therefore the instanciation?
//Should be catched anyway... ;-)
//Btw, this crashes miniAudicle too...
[[0,1],[1,1]] @=> int testarray[3][2];
|
any ideas or comments about this?
regards
/moudi |
|
Back to top
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Mon Jan 08, 2007 6:04 pm Post subject:
|
 |
|
Yeah, this needs a mail to Spencer because both are bugs.
The bottom one is simple; that's simply a case of bad syntax not being caught.
The first example is more complicated; you are right and it should work like this *but* static data isn't completely implemented yet. If you try the exact same with command-line ChucK you should get a proper error, I'm not sure why the mini let's it slide untill it's too late.
To get "real" static arrays you need to use a workaround involving asignment. Basically you define your static object inside of the class but instantiate it outside. I can dig up a example if you'd like. _________________ Kassen |
|
Back to top
|
|
 |
moudi
Joined: Oct 07, 2006 Posts: 63 Location: Bern Switzerland
|
Posted: Tue Jan 09, 2007 1:08 pm Post subject:
|
 |
|
Kassen wrote: | Yeah, this needs a mail to Spencer because both are bugs. |
so you mean i should write it to the mailing list?
Kassen wrote: |
To get "real" static arrays you need to use a workaround involving asignment. Basically you define your static object inside of the class but instantiate it outside. I can dig up a example if you'd like. |
that's exactly what i already did
regards
/moudi |
|
Back to top
|
|
 |
spencer

Joined: Aug 16, 2006 Posts: 53 Location: northern california
|
Posted: Thu Jan 11, 2007 6:18 am Post subject:
|
 |
|
Howdy,
moudi wrote: | Code: |
public class crash
{
0 => static int myint;
[0,1,2] @=> static int myarray[];
}
//Chuck Values to this Variables without instanciation.
//The pure integer works:
1 => crash.myint;
//This one crashs miniAudicle!!:
10 => crash.myarray[1]; |
|
Argh! Thanks for finding this. There are still a few bugs in ChucK's array and class implementations, but I thought most of the crashing ones were under control. I'll start looking into a fix, but it sounds like you have workaround for now.
Also, both command-line chuck and miniAudicle crash on this--miniAudicle uses the exact same ChucK implementation as chuck so thats expected behavior.
moudi wrote: | Code: |
//Btw, this crashes miniAudicle too...
[[0,1],[1,1]] @=> int testarray[3][2]; |
|
Hmm, I can't seem to be able to get it to crash by itself. Its not completely clear what should happen here, but I think its actually legal in terms of syntax. However, on my tests it seems that the array is zeroed out and never initialized with the new values unless the array declaration and initialization is done in two separate statements. After that ChucK treats the array like a 2x2 array, which makes some sort of sense, if one thinks of an array not as a vector of data, but a reference to an array object. |
|
Back to top
|
|
 |
ge

Joined: Aug 13, 2006 Posts: 108 Location: Palo Alto, CA
|
Posted: Thu Jan 11, 2007 8:40 am Post subject:
Re: static arrays |
 |
|
moudi wrote: | Code: |
public class crash
{
0 => static int myint;
[0,1,2] @=> static int myarray[];
} |
|
This is a known bug, I believe. Currently, there are problems with directly initializing or even instantiating static members that are non-primitives (e.g. not int, float, time, dur). The workaround is to declare as reference and initialize outside:
Code: |
public class X
{
static int arr[][];
}
// initialize
new int[4][5] @=> X.arr;
|
Hopefully that should work... |
|
Back to top
|
|
 |
moudi
Joined: Oct 07, 2006 Posts: 63 Location: Bern Switzerland
|
Posted: Mon Jan 15, 2007 3:04 pm Post subject:
|
 |
|
spencer wrote: |
moudi wrote: | Code: |
//Btw, this crashes miniAudicle too...
[[0,1],[1,1]] @=> int testarray[3][2]; |
|
Hmm, I can't seem to be able to get it to crash by itself. Its not completely clear what should happen here, but I think its actually legal in terms of syntax. However, on my tests it seems that the array is zeroed out and never initialized with the new values unless the array declaration and initialization is done in two separate statements. After that ChucK treats the array like a 2x2 array, which makes some sort of sense, if one thinks of an array not as a vector of data, but a reference to an array object. |
do you mean that your miniaudicle survives the attack above
perhaps it's windows specific?
by the way: i discovered it by a simple typing mistake, it was no intention
ge wrote: |
Hopefully that should work... |
yep, it does
any news about the filterbehaviour from the other thread?
http://electro-music.com/forum/topic-15426.html&sid=9d5ff565d0fc46290fd49b980c4f9cb3
(sorry for the crossposting).
cheers
/moudi |
|
Back to top
|
|
 |
|