Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
_NEWIMAGE() should be fixed to always take 3 parms
#1
Bug 
If two parameters are given to "_NEWIMAGE()" and any graphics command is called (in the program below "PSET") the program gives an error box which, if not taken seriously, the program hangs for a moment then terminates, writing on the terminal "killed". The source code was something I found from the "dot-com" forum that was meant for "QBJS" and not on Linux.

Code: (Select All)
''by "mikesharpe" from qb64-dot-com forum
dim shared pi, p, q, d, z0, t, f, sw, sh

sw = 800
sh = 600
d = 700
z0 = 1500
pi = 4*atn(1)

screen _newimage(sw, sh, 12)

sv = 2*pi/30
su = 2*pi/10


for t = 0 to 2*pi step 0.01
    cls
    u = 0
    for v=0 to 2*pi+sv step sv
        x = cos(u)
        y = sin(u)
        z = cos(v)
        w = sin(v)
        
        proj x, y, z, w
        pset (p, q)
        
        for u=0 to 2*pi+su step su
            x = cos(u)
            y = sin(u)
            z = cos(v)
            w = sin(v)
        
            proj x, y, z, w
            line -(p, q)
        next
    next
    
    for u=0 to 2*pi+su step su
        x = cos(u)
        y = sin(u)
        z = cos(v)
        w = sin(v)
        
        proj x, y, z, w
        pset (p, q), _rgb(255,0,0)
        
        for v=0 to 2*pi+sv step sv
            x = cos(u)
            y = sin(u)
            z = cos(v)
            w = sin(v)
        
            proj x, y, z, w
            line -(p, q), _rgb(255,0,0)
        next
    next
    
    _display
    _limit 50
next
_autodisplay
system

sub proj(x, y, z, w)
    xx = x
    yy = y*cos(t) - w*sin(t)
    zz = z
    ww = y*sin(t) + w*cos(t)

    d2 = 3
    w0 = 3
    xx = xx*d2/(w0 + ww)
    yy = yy*d2/(w0 + ww)
    zz = zz*d2/(w0 + ww)
    
    xxx = xx*cos(t) - zz*sin(t)
    zzz = xx*sin(t) + zz*cos(t)
    xx = xxx
    zz = zzz
    
    a = pi/12
    b = pi/3
    xxx = xx*cos(a) - yy*sin(a)
    yyy = xx*sin(a) + yy*cos(a)
    xx = xxx
    yy = yyy

    yyy = yy*cos(b) - zz*sin(b)
    zzz = yy*sin(b) + zz*cos(b)
    yy = yyy
    zz = zzz
    
    xx = 200*xx
    yy = 200*yy
    zz = 200*zz

    p = sw/2 + 2*xx*d/(yy + z0)
    q = sh/2 - 2*zz*d/(yy + z0)
end sub

My other addition to the original program was "_DISPLAY" just above "_LIMIT" so this was more tolerable.
Reply
#2
Thumbs Up 
+1 don't know how many times I've forgotten the third and crashed!

Would be nice to just throw an error.
b = b + ...
Reply
#3
I said the source code I listed might have been meant for "QBJS" but got confused by another post made by the user of the other forum. I just went into "QBJS" and it complains "Missing or unsupported method" for "LINE" and "PSET", so I can't understand why that source code was provided with "_NEWIMAGE()" being given only two parameters and maybe never tested. The warning is given whether or not "_NEWIMAGE()" has two or three parameters, it's simply that "QBJS" doesn't support those graphics statements yet. Maybe I should have started this thread on the new sub-forum. However, this is a possibility for code that perhaps was composed first in "BAM" or "QBJS", and then somebody tries to run it on QB64(PE).
Reply
#4
OK yeah vince code worked without the 3rd parameter in QBJS, I think, the hypercube that PhilOfPerth noted.. but still an error thrown is better than crashing in regular IDE QB64pe.
b = b + ...
Reply
#5
Quote:… it's simply that "QBJS" doesn't support those graphics statements yet.

Interesting… Line and PSet are supported in QBJS. I was able to run the program above in QBJS with no errors.
Reply
#6
Confirmed but on Windows:
   
b = b + ...
Reply
#7
Oh, cool. Are we making a torus?
Tread on those who tread on you

Reply
#8
(11-09-2022, 02:05 PM)mnrvovrfc Wrote: If two parameters are given to "_NEWIMAGE()" and any graphics command is called (in the program below "PSET") the program gives an error box which, if not taken seriously, the program hangs for a moment then terminates, writing on the terminal "killed". 

This isn't as "broken" as you assume.  Wink

Code: (Select All)
Screen _NewImage(80, 40)

Print _Width, _Height, _PixelSize
A newimage, without any third parameter, defaults to a SCREEN 0 image -- which is text only.   Trying any graphics command in a text-only screen will generate that error box, but what probably causes it to hang up and then terminate is attemping to create an 800x600 text screen!

800 characters wide, 600 rows high..  I can see where that would push the limits of what's possible and terminate without much warning.  Wink
Reply
#9
(11-09-2022, 05:21 PM)dbox Wrote:
Quote:… it's simply that "QBJS" doesn't support those graphics statements yet.

Interesting… Line and PSet are supported in QBJS.  I was able to run the program above in QBJS with no errors.
I had forgotten to post on the sub-forum that KDE Falkon might not be a supported web browser. It doesn't look like it's based on Chromium as I've been misled to believe until now. I tried it on EndeavourOS (Arch-based) XFCE but with Falkon instead of the provided Firefox as web browser.
Reply
#10
(11-09-2022, 05:58 PM)SMcNeill Wrote:
(11-09-2022, 02:05 PM)mnrvovrfc Wrote: If two parameters are given to "_NEWIMAGE()" and any graphics command is called (in the program below "PSET") the program gives an error box which, if not taken seriously, the program hangs for a moment then terminates, writing on the terminal "killed". 

This isn't as "broken" as you assume.  Wink

Code: (Select All)
Screen _NewImage(80, 40)

Print _Width, _Height, _PixelSize
A newimage, without any third parameter, defaults to a SCREEN 0 image -- which is text only.   Trying any graphics command in a text-only screen will generate that error box, but what probably causes it to hang up and then terminate is attemping to create an 800x600 text screen!

800 characters wide, 600 rows high..  I can see where that would push the limits of what's possible and terminate without much warning.  Wink

Oh yeah, it's when I try and use 1200 pixels wide and whatever high and forget the 3rd that's when it gets bad!
b = b + ...
Reply




Users browsing this thread: 1 Guest(s)