electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Links  |  Store
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks GalleryGallery 
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
A tricky bug to trace
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [4 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
Antimon



Joined: Jan 18, 2005
Posts: 924
Location: Sweden
Audio files: 6
G2 patch files: 48

PostPosted: Sat Dec 08, 2007 12:40 pm    Post subject: A tricky bug to trace Reply with quote  Mark this post and the followings unread

I spent an hour trying to figure out why code like this doesn't work:

Code:
while (true) {
   <<< "Why, howdy mister!" >>>;
   misterFunction();
   1::second => now;
}

8 => int variable;

fun void misterFunction() {
   <<< "Today, my variable is ", variable >>>;
}


This will output something like this:


Code:
"Why, howdy mister!" : (string)
Today, my variable is  0
"Why, howdy mister!" : (string)
Today, my variable is  0


The value of variable is actually random, as I tried to rearrange stuff it changed to other values, seemingly taking them from other initializations.

I guess that this is because, since execution is stuck in the main loop, the actual initialization of variable will never happen, leaving it undefined. Comparing with Java, I think variables and members that are initialized with values are handled before any code in the encapsulating class or instance is executed (static variables need to be declared before they are used, I think). I don't know if it is possible to have ChucK do this...

/Stefan

_________________
You are Wendy Mackaye, first girl on the red planet.
Back to top
View user's profile Send private message Visit poster's website
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 6237
Location: The Hague, NL
G2 patch files: 3

PostPosted: Sat Dec 08, 2007 1:46 pm    Post subject: Reply with quote  Mark this post and the followings unread

Definitely a bug, another one that relates to initialisation and the order in which things are written. I thought all of those would be gone by now, there used to be similar ones that would actually crash the whole VM.

Could you add it to the WiKi on the list of things to be fixed next release? If you don't like WiKi's I could do it for you as well and link here?

In general it's wise not to define variables below your main loop, classes and functions are fine but not variables on their own, I'm surprised this ran at all :¬) The mysteries of ChucK....

_________________
while(!machine.crash() ) <<<"all is well">>>;
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Antimon



Joined: Jan 18, 2005
Posts: 924
Location: Sweden
Audio files: 6
G2 patch files: 48

PostPosted: Sat Dec 08, 2007 4:59 pm    Post subject: Reply with quote  Mark this post and the followings unread

OK, I put it up on the wiki. Smile I was shuffling code around a bit, experimenting - I'll probably keep the main loop at the bottom from now on.

Oh, wait! Should I put it up on the page for next release? I put it on the bug request/report page... I'm not completely sure that this situation can be easily detected by a compiler.

/Stefan

_________________
You are Wendy Mackaye, first girl on the red planet.
Back to top
View user's profile Send private message Visit poster's website
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 6237
Location: The Hague, NL
G2 patch files: 3

PostPosted: Sat Dec 08, 2007 6:15 pm    Post subject: Reply with quote  Mark this post and the followings unread

I'd put it in the list for the next release, it's just plain wrong and I agree it should be a fairly simple fix, no need to debate it or whatever.

Something quite odd is going on in this area, I had a issue where manually created Shred objects had a random id as well.

Anyway I tend to go;

-define stuff and set it up.

-define function to be sporked.

-spork it.

-repeat the last two steps as needed.

-main loop.

-classes.

-utility functions.

This order feels quite natural to me and eliminates problems like yours, I keep classes and functions that low as I tend to write those to deal with things that would otherwise be annoying or monotonous and at the bottom they are out of the way (unless they turn out to have a bug...).

_________________
while(!machine.crash() ) <<<"all is well">>>;
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [4 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum

Please support our site. If you click through and buy from
our affiliate partners, we earn a small commission.


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003, 2004, 2005, 2006 and 2007 by electro-music.com