Old 10-25-2010, 10:11 AM   #1
Bernstraw
Human being with feelings
 
Join Date: Sep 2010
Posts: 388
Default Help : graphical glitches in my JS

HI,
I'm working on a midi JS (aroung 20k), using a graphical user interface.
Pb is I'm getting a lot of random glitches as if the gfx_x and gfx_y values were sometimes not properly set and rectangles drawn at random coordinates ! :
[IMG]http://img264.**************/img264/5461/gfxglitch2.th.gif[/IMG]

I've managed to catch it on snapshots (normal display VS 2 glitchy frames) :
[IMG]http://img263.**************/img263/1981/bug2m.th.png[/IMG][IMG]http://img830.**************/img830/2784/bug1x.th.png[/IMG][IMG]http://img826.**************/img826/9445/bug0u.th.png[/IMG]

Numbers and dot coordinates are all listed in arrays and displayed via various loops.
I'm using gfx_lineto, gfx_rectto, gfx_drawnumber, gfx_drawchar.
It seems to worsen when moving the mouse fast, but not always.
The @block contains tests on mouse_x mouse_y (for mouse focus), and all the interface to create, move and manage dots.
I'm using midisend in a loop to send CC messages. That's about it.

So what could be the pb ? why so random ?
Bernstraw is offline   Reply With Quote
Old 10-25-2010, 01:35 PM   #2
ubergod
Human being with feelings
 
ubergod's Avatar
 
Join Date: Nov 2007
Posts: 741
Default

Can you post the source code so we can take a look?
ubergod is offline   Reply With Quote
Old 10-25-2010, 01:39 PM   #3
Bernstraw
Human being with feelings
 
Join Date: Sep 2010
Posts: 388
Default

Sure, thanks !

source :
http://miroir.perso.neuf.fr/msc/JS/v...ectormorph_004

EDIT : Hit CTRL+click to add dots.
Bernstraw is offline   Reply With Quote
Old 10-25-2010, 02:33 PM   #4
ubergod
Human being with feelings
 
ubergod's Avatar
 
Join Date: Nov 2007
Posts: 741
Default

Try this, replace the variable "i" with "i2" or something else for this loop segment:

Code:
 i2=0;
 loop(dot_N,
  dot_bypass[M*i2]<0 ? (
   gfx_r=gfx_b=gfx_g=0.6; gfx_a=0.5;
   gfx_x=dot_x[M*i2]; gfx_y=16; gfx_lineto(gfx_x,gfx_h-2,0);
   gfx_x=76; gfx_y=dot_y[M*i2]; gfx_lineto(gfx_w-2,gfx_y,0);
   gfx_a=1;
   d=8*dot_ratio[M*i2];
   gfx_x=dot_x[M*i2]-d-1; gfx_y=dot_y[M*i2]-d-1;
   gfx_r=gfx_g=gfx_b=0;
   gfx_rectto(dot_x[M*i2]+d+1,dot_y[M*i2]+d+1);
   gfx_x=dot_x[M*i2]-d; gfx_y=dot_y[M*i2]-d;
   gfx_r=dot_r[M*i2]; gfx_g=dot_g[M*i2]; gfx_b=dot_b[M*i2];
   gfx_rectto(dot_x[M*i2]+d,dot_y[M*i2]+d);
   gfx_y=dot_y[M*i2]-9; gfx_x+=5;
   gfx_r=gfx_g=gfx_b=0;
   gfx_drawnumber(i2+1,0); gfx_x+=3;
   jj=0; while (
    gfx_drawchar(dot_name[M*i2+jj]);
    jj+=1;
    dot_name[M*i2+jj]!=0 && jj<dot_namesize;
   );
  );
  i2+=1;
 );
I suspect because you used "i" to do some looping in a previous part of the code, it causes a problem here - as if the latter loop was using the previous loops "i". I've seen this myself doing js plugs, and using a different variable name always seemed to fix it. I can't explain why the problem happens though, just one of the many quirky things.

Hopefully that helps... really interesting plugin btw
ubergod is offline   Reply With Quote
Old 10-25-2010, 03:06 PM   #5
Bernstraw
Human being with feelings
 
Join Date: Sep 2010
Posts: 388
Default

Quote:
Originally Posted by ubergod View Post
Try this, replace the variable "i" with "i2"
I suspect because you used "i" to do some looping in a previous part of the code, it causes a problem here - as if the latter loop was using the previous loops "i". I've seen this myself doing js plugs, and using a different variable name always seemed to fix it. I can't explain why the problem happens though, just one of the many quirky things.

Hopefully that helps... really interesting plugin btw
Thanks a bunch ! It worked !
Just remembered it's in the doc :
Quote:
Note that this code runs in a separate thread from the audio processing, so you may have both running simultaneously which could leave certain variables/RAM in an unpredictable state.
Will release this soon, thanks for your help !
Bernstraw is offline   Reply With Quote
Old 10-26-2010, 12:41 AM   #6
IXix
Human being with feelings
 
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,889
Default

That's a sneaky problem. I had similar trouble and it took me a while to figure out what was going wrong. Now I tend to use a naming convention for graphics related variables to avoid confusion.
IXix is offline   Reply With Quote
Old 10-27-2010, 01:33 PM   #7
Mich
Human being with feelings
 
Join Date: May 2009
Posts: 1,265
Default

JS runs in a flat namespace and @sample and @gfx code is running concurrently. Thus you need to name all variables appropriately.
Also take note that due to the @sample (and all the other @ sections) running concurrently with @gfx you will sometimes still exhibit problems (at least I did) because you need to properly sync the data transfer between @sample and @gfx (in case you want to display data related to the audio source) which can be though (and sometimes impossible) to do correct in JS.
Mich is offline   Reply With Quote
Old 11-01-2010, 02:12 AM   #8
Bernstraw
Human being with feelings
 
Join Date: Sep 2010
Posts: 388
Default

Quote:
Originally Posted by Mich View Post
you need to properly sync the data transfer between @sample and @gfx (in case you want to display data related to the audio source) which can be though (and sometimes impossible) to do correct in JS.
I had this pb : having to use a @block variable in @gfx and vice-versa. I ended up doing it differently but that's really annoying and I may need it at some point.
Would it work like this ? :
Code:
@block

block_variable1_sync = 0 ;
// block_variable1 is calculated here //
block_variable1_sync = 1 ;


@gfx

while( block_variable1_sync == 0 ) ;
gfx_variable1 = block_variable1 ;
// gfx_variable1 is used here //
Bernstraw is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 10:00 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.