Author Topic: Anyone know what's wrong here? (Rho knows!)  (Read 6424 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Anyone know what's wrong here?
« Reply #15 on: December 24, 2019, 02:37:32 pm »
Here is another oddity: I changed the Window System.BI
Code: QB64: [Select]
  1. DIM SHARED Windows AS Window_Type
  2. DIM SHARED Captions AS Caption_Type
  3. DIM SHARED WindowCount AS INTEGER, DisplayCount AS INTEGER
  4. DIM SHARED CaptionsCount AS INTEGER
  5.  

From DIM SHARED to COMMON SHARED, got an error so I switched them back to DIM SHARED and now line 35 is showing error
  [ You are not allowed to view this attachment ]  

I did this twice to make sure I did return the .BI back to what it was. So now it won't get past line 35.

Did it again only with first, Windows to COMMON and then back to DIM and again it's stuck on line 35.
« Last Edit: December 24, 2019, 02:49:09 pm by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Anyone know what's wrong here?
« Reply #16 on: December 24, 2019, 03:40:54 pm »
Okies, I thought I was baffled before, but now I'm just....

/SIGH!!!!!!!!

WTF type of glitch have I managed to stumble across in QB64???  The more I try and sort out what the BLEEP is going on, the worse my brain breaks.  I'm now getting impossible errors:

Code: QB64: [Select]
  1.     x = Captions(n).FontHandle
  2.     COLOR Red
  3.     LOCATE 10, 1: PRINT x, F, x = F; "Before IF"
  4.     IF x <> F THEN
  5.         LOCATE 11, 1: PRINT x, F, x = F; "In IF"
  6.         _FONT x
  7.     END IF
  8.     COLOR Black

The issue is in the _FONT statement, right??

So I test the little code above, and I want to see how the value of X changes, or what the BLEEP the value the _FONT statement is receiving, at least...  When we start the SUB, the font value is 16 (which is F).  We get the value for X, which is 16.  The "Before IF" print statement works, saying the values are equal...

We don't print the "In IF" statement, so we should be skipping the code inside that IF block completely...

AND YET....

We get an Invalid Handler error message for the _FONT x line, which is inside the IF block we're not even entering?!!



Here's the whole code for testing, with the '$INCLUDE statements merged into the main program, and with all of the variable length STRINGs removed from the TYPEs.  Anything someone suggests which might be the source of this glitch, I'm testing to try and rule it out, and so far nothing has changed the behavior one bit.

Code: QB64: [Select]
  1. $LET COLOR = 32
  2. $LET COMMONCONST = TRUE
  3. $LET KEYCODES = TRUE
  4. $LET MINMAX = TRUE
  5.  
  6. $IF COMMONCONST = TRUE THEN
  7.     CONST True = -1, False = 0
  8.  
  9. $IF MINMAX = TRUE THEN
  10.     CONST Bit_Min` = -1`, Bit_Max = 0`
  11.     CONST Byte_Min%% = -128%%, Byte_Max = 127%%
  12.     CONST Integer_Min% = -32768%, Integer_Max = 32767%
  13.     CONST Long_Min& = -2147483648&, Long_Max = 2147483647&
  14.     CONST Integer64_Min&& = -9223372036854775808&&, Integer64_Max = 9223372036854775807&&
  15.  
  16.     CONST Single_Min! = -2.802597E-45, Single_Max = 3.402823E+38
  17.     CONST Double_Min# = -4.490656458412465E-324, Double_Max = 1.797693134862310E+308
  18.     CONST Float_Min## = -1.18E-4932, Float_Max = 1.18E+4932
  19.  
  20.     CONST U_Bit_Min~` = 0, U_Bit_Max = 1
  21.     CONST U_Byte_Min~%% = 0, U_Byte_Max = 256
  22.     CONST U_Integer_Min~% = 0, U_Integer_Max = 65535
  23.     CONST U_Long_Min~& = 0, U_Long_Max = 4294967295
  24.     CONST U_Integer64_Min~&& = 0, U_Integer64_Max = 18446744073709551615
  25.  
  26.     CONST String_Min& = 0, String_Max& = 2147483647
  27.  
  28. $IF KEYCODES = TRUE THEN
  29.     CONST Key_Uppercase = 0, Key_LowerCase = 32, Key_UC = 0, Key_LC = 32
  30.  
  31.     CONST Key_Backspace = 8, Key_Bksp = 8
  32.     CONST Key_Tab = 9, Key_Enter = 13, Key_ESC = 27, Key_Space = 32
  33.     CONST Key_Exclamation = 33, Key_Quote = 34, Key_Number = 35, Key_Dollar = 36
  34.     CONST Key_Percent = 37, Key_And = 38, Key_Apostrophe = 39
  35.     CONST Key_Left_Parenthese = 40, Key_Right_Parenthese = 41
  36.     CONST Key_Times = 42, Key_Star = 42, Key_Plus = 43, Key_Comma = 44
  37.     CONST Key_Minus = 45, Key_Dash = 45, Key_Period = 46, Key_Divide = 47, Key_Slash = 47
  38.     CONST Key_0 = 48, Key_1 = 49, Key_2 = 50, Key_3 = 51, Key_4 = 52
  39.     CONST Key_5 = 53, Key_6 = 54, Key_7 = 55, Key_8 = 56, Key_9 = 57
  40.     CONST Key_Colon = 58, Key_Semicolon = 59, Key_LessThan = 60, Key_Equal = 61
  41.     CONST Key_GreaterThan = 62, Key_Question = 63, Key_QuestionMark = 63, Key_At = 64
  42.     CONST Key_A = 65, Key_B = 66, Key_C = 67, Key_D = 68, Key_E = 69, Key_F = 70
  43.     CONST Key_G = 71, Key_H = 72, Key_I = 73, Key_J = 74, Key_K = 75, Key_L = 76
  44.     CONST Key_M = 77, Key_N = 78, Key_O = 79, Key_P = 80, Key_Q = 81, Key_R = 82
  45.     CONST Key_S = 83, Key_T = 84, Key_U = 85, Key_V = 86, Key_W = 87, Key_X = 88
  46.     CONST Key_Y = 89, Key_Z = 90
  47.     CONST Key_LeftBrace = 91, Key_BackSlash = 92, Key_RightBrace = 92
  48.     CONST Key_Power = 94, Key_Underscore = 95, Key_BackQuote = 96
  49.     'Lowercase A to Z are Key_A + Key_LowerCase to Key_Z + Key_LowerCase
  50.  
  51.     CONST Key_F1 = 15104, Key_F2 = 15360, Key_F3 = 15616, Key_F4 = 15872, Key_F5 = 16128
  52.     CONST Key_F6 = 16384, Key_F7 = 16640, Key_F8 = 16896, Key_F9 = 17152, Key_F10 = 17408
  53.     CONST Key_F11 = 34048, Key_F12 = 34304
  54.  
  55.     CONST Key_Pause = 100019
  56.     CONST Key_NumLock = 100300, Key_CapsLock = 100301, Key_ScrollLock = 100302
  57.     CONST Key_RightShift = 100303, Key_LeftShift = 100304
  58.     CONST Key_RightControl = 100305, Key_RightCtrl = 100305, Key_LeftControl = 100306, Key_LeftCtrl = 100306
  59.     CONST Key_RightAlt = 100307, Key_LeftAlt = 100308
  60.     CONST Key_LeftApple = 100309, Key_RightApple = 100310
  61.     CONST Key_LeftWin = 100311, Key_RightWin = 100312
  62.     CONST Key_Sys = 100316, Key_Menu = 100319
  63.  
  64.     CONST Key_Up = 18432, Key_Left = 19200, Key_Down = 20480, Key_Right = 19712
  65.     CONST Key_Ins = 20992, Key_Home = 18176, Key_PageUp = 18688
  66.     CONST Key_Del = 21248, Key_End = 20224, Key_PageDown = 20736
  67.  
  68.     CONST AliceBlue = &HFFF0F8FF~& ' _RGB32(240,248,255)
  69.     CONST Almond = &HFFEFDECD~& '_RGB32(239,222,205)
  70.     CONST AntiqueBrass = &HFFCD9575~& '_RGB32(205,149,117)
  71.     CONST AntiqueWhite = &HFFFAEBD7~& ' _RGB32(250,235,215)
  72.     CONST Apricot = &HFFFDD9B5~& '_RGB32(253,217,181)
  73.     CONST Aqua = &HFF00FFFF~& ' _RGB32(0,255,255)
  74.     CONST Aquamarine = &HFF7FFFD4~& ' _RGB32(127,255,212)
  75.     CONST Asparagus = &HFF87A96B~& '_RGB32(135,169,107)
  76.     CONST AtomicTangerine = &HFFFFA474~& '_RGB32(255,164,116)
  77.     CONST Azure = &HFFF0FFFF~& ' _RGB32(240,255,255)
  78.     CONST BananaMania = &HFFFAE7B5~& '_RGB32(250,231,181)
  79.     CONST Beaver = &HFF9F8170~& '_RGB32(159,129,112)
  80.     CONST Beige = &HFFF5F5DC~& ' _RGB32(245,245,220)
  81.     CONST Bisque = &HFFFFE4C4~& ' _RGB32(255,228,196)
  82.     CONST Bittersweet = &HFFFD7C6E~& '_RGB32(253,124,110)
  83.     CONST Black = &HFF000000~& ' _RGB32(0,0,0)
  84.     CONST BlanchedAlmond = &HFFFFEBCD~& ' _RGB32(255,235,205)
  85.     CONST BlizzardBlue = &HFFACE5EE~& '_RGB32(172,229,238)
  86.     CONST Blue = &HFF0000FF~& ' _RGB32(0,0,255)
  87.     CONST BlueBell = &HFFA2A2D0~& '_RGB32(162,162,208)
  88.     CONST BlueGray = &HFF6699CC~& '_RGB32(102,153,204)
  89.     CONST BlueGreen = &HFF0D98BA~& '_RGB32(13,152,186)
  90.     CONST BlueViolet = &HFF8A2BE2~& ' _RGB32(138,43,226)
  91.     CONST Blush = &HFFDE5D83~& '_RGB32(222,93,131)
  92.     CONST BrickRed = &HFFCB4154~& '_RGB32(203,65,84)
  93.     CONST Brown = &HFFA52A2A~& ' _RGB32(165,42,42)
  94.     CONST BurlyWood = &HFFDEB887~& ' _RGB32(222,184,135)
  95.     CONST BurntOrange = &HFFFF7F49~& '_RGB32(255,127,73)
  96.     CONST BurntSienna = &HFFEA7E5D~& '_RGB32(234,126,93)
  97.     CONST CadetBlue = &HFF5F9EA0~& ' _RGB32(95,158,160)
  98.     CONST Canary = &HFFFFFF99~& '_RGB32(255,255,153)
  99.     CONST CaribbeanGreen = &HFF1CD3A2~& '_RGB32(28,211,162)
  100.     CONST CarnationPink = &HFFFFAACC~& '_RGB32(255,170,204)
  101.     CONST Cerise = &HFFDD4492~& '_RGB32(221,68,146)
  102.     CONST Cerulean = &HFF1DACD6~& '_RGB32(29,172,214)
  103.     CONST ChartReuse = &HFF7FFF00~& ' _RGB32(127,255,0)
  104.     CONST Chestnut = &HFFBC5D58~& '_RGB32(188,93,88)
  105.     CONST Chocolate = &HFFD2691E~& ' _RGB32(210,105,30)
  106.     CONST Copper = &HFFDD9475~& '_RGB32(221,148,117)
  107.     CONST Coral = &HFFFF7F50~& ' _RGB32(255,127,80)
  108.     CONST Cornflower = &HFF9ACEEB~& '_RGB32(154,206,235)
  109.     CONST CornflowerBlue = &HFF6495ED~& ' _RGB32(100,149,237)
  110.     CONST Cornsilk = &HFFFFF8DC~& ' _RGB32(255,248,220)
  111.     CONST CottonCandy = &HFFFFBCD9~& '_RGB32(255,188,217)
  112.     CONST CrayolaAquamarine = &HFF78DBE2~& '_RGB32(120,219,226)
  113.     CONST CrayolaBlue = &HFF1F75FE~& '_RGB32(31,117,254)
  114.     CONST CrayolaBlueViolet = &HFF7366BD~& '_RGB32(115,102,189)
  115.     CONST CrayolaBrown = &HFFB4674D~& '_RGB32(180,103,77)
  116.     CONST CrayolaCadetBlue = &HFFB0B7C6~& '_RGB32(176,183,198)
  117.     CONST CrayolaForestGreen = &HFF6DAE81~& '_RGB32(109,174,129)
  118.     CONST CrayolaGold = &HFFE7C697~& '_RGB32(231,198,151)
  119.     CONST CrayolaGoldenrod = &HFFFCD975~& '_RGB32(252,217,117)
  120.     CONST CrayolaGray = &HFF95918C~& '_RGB32(149,145,140)
  121.     CONST CrayolaGreen = &HFF1CAC78~& '_RGB32(28,172,120)
  122.     CONST CrayolaGreenYellow = &HFFF0E891~& '_RGB32(240,232,145)
  123.     CONST CrayolaIndigo = &HFF5D76CB~& '_RGB32(93,118,203)
  124.     CONST CrayolaLavender = &HFFFCB4D5~& '_RGB32(252,180,213)
  125.     CONST CrayolaMagenta = &HFFF664AF~& '_RGB32(246,100,175)
  126.     CONST CrayolaMaroon = &HFFC8385A~& '_RGB32(200,56,90)
  127.     CONST CrayolaMidnightBlue = &HFF1A4876~& '_RGB32(26,72,118)
  128.     CONST CrayolaOrange = &HFFFF7538~& '_RGB32(255,117,56)
  129.     CONST CrayolaOrangeRed = &HFFFF2B2B~& '_RGB32(255,43,43)
  130.     CONST CrayolaOrchid = &HFFE6A8D7~& '_RGB32(230,168,215)
  131.     CONST CrayolaPlum = &HFF8E4585~& '_RGB32(142,69,133)
  132.     CONST CrayolaRed = &HFFEE204D~& '_RGB32(238,32,77)
  133.     CONST CrayolaSalmon = &HFFFF9BAA~& '_RGB32(255,155,170)
  134.     CONST CrayolaSeaGreen = &HFF9FE2BF~& '_RGB32(159,226,191)
  135.     CONST CrayolaSilver = &HFFCDC5C2~& '_RGB32(205,197,194)
  136.     CONST CrayolaSkyBlue = &HFF80DAEB~& '_RGB32(128,218,235)
  137.     CONST CrayolaSpringGreen = &HFFECEABE~& '_RGB32(236,234,190)
  138.     CONST CrayolaTann = &HFFFAA76C~& '_RGB32(250,167,108)
  139.     CONST CrayolaThistle = &HFFEBC7DF~& '_RGB32(235,199,223)
  140.     CONST CrayolaViolet = &HFF926EAE~& '_RGB32(146,110,174)
  141.     CONST CrayolaYellow = &HFFFCE883~& '_RGB32(252,232,131)
  142.     CONST CrayolaYellowGreen = &HFFC5E384~& '_RGB32(197,227,132)
  143.     CONST Crimson = &HFFDC143C~& ' _RGB32(220,20,60)
  144.     CONST Cyan = &HFF00FFFF~& ' _RGB32(0,255,255)
  145.     CONST Dandelion = &HFFFDDB6D~& '_RGB32(253,219,109)
  146.     CONST DarkBlue = &HFF00008B~& ' _RGB32(0,0,139)
  147.     CONST DarkCyan = &HFF008B8B~& ' _RGB32(0,139,139)
  148.     CONST DarkGoldenRod = &HFFB8860B~& ' _RGB32(184,134,11)
  149.     CONST DarkGray = &HFFA9A9A9~& ' _RGB32(169,169,169)
  150.     CONST DarkGreen = &HFF006400~& ' _RGB32(0,100,0)
  151.     CONST DarkKhaki = &HFFBDB76B~& ' _RGB32(189,183,107)
  152.     CONST DarkMagenta = &HFF8B008B~& ' _RGB32(139,0,139)
  153.     CONST DarkOliveGreen = &HFF556B2F~& ' _RGB32(85,107,47)
  154.     CONST DarkOrange = &HFFFF8C00~& ' _RGB32(255,140,0)
  155.     CONST DarkOrchid = &HFF9932CC~& ' _RGB32(153,50,204)
  156.     CONST DarkRed = &HFF8B0000~& ' _RGB32(139,0,0)
  157.     CONST DarkSalmon = &HFFE9967A~& ' _RGB32(233,150,122)
  158.     CONST DarkSeaGreen = &HFF8FBC8F~& ' _RGB32(143,188,143)
  159.     CONST DarkSlateBlue = &HFF483D8B~& ' _RGB32(72,61,139)
  160.     CONST DarkSlateGray = &HFF2F4F4F~& ' _RGB32(47,79,79)
  161.     CONST DarkTurquoise = &HFF00CED1~& ' _RGB32(0,206,209)
  162.     CONST DarkViolet = &HFF9400D3~& ' _RGB32(148,0,211)
  163.     CONST DeepPink = &HFFFF1493~& ' _RGB32(255,20,147)
  164.     CONST DeepSkyBlue = &HFF00BFFF~& ' _RGB32(0,191,255)
  165.     CONST Denim = &HFF2B6CC4~& '_RGB32(43,108,196)
  166.     CONST DesertSand = &HFFEFCDB8~& '_RGB32(239,205,184)
  167.     CONST DimGray = &HFF696969~& ' _RGB32(105,105,105)
  168.     CONST DodgerBlue = &HFF1E90FF~& ' _RGB32(30,144,255)
  169.     CONST Eggplant = &HFF6E5160~& '_RGB32(110,81,96)
  170.     CONST ElectricLime = &HFFCEFF1D~& '_RGB32(206,255,29)
  171.     CONST Fern = &HFF71BC78~& '_RGB32(113,188,120)
  172.     CONST FireBrick = &HFFB22222~& ' _RGB32(178,34,34)
  173.     CONST Floralwhite = &HFFFFFAF0~& ' _RGB32(255,250,240)
  174.     CONST ForestGreen = &HFF228B22~& ' _RGB32(34,139,34)
  175.     CONST Fuchsia = &HFFC364C5~& '_RGB32(195,100,197)
  176.     CONST FuzzyWuzzy = &HFFCC6666~& '_RGB32(204,102,102)
  177.     CONST Gainsboro = &HFFDCDCDC~& ' _RGB32(220,220,220)
  178.     CONST GhostWhite = &HFFF8F8FF~& ' _RGB32(248,248,255)
  179.     CONST Gold = &HFFFFD700~& ' _RGB32(255,215,0)
  180.     CONST GoldenRod = &HFFDAA520~& ' _RGB32(218,165,32)
  181.     CONST GrannySmithApple = &HFFA8E4A0~& '_RGB32(168,228,160)
  182.     CONST Gray = &HFF808080~& ' _RGB32(128,128,128)
  183.     CONST Green = &HFF008000~& ' _RGB32(0,128,0)
  184.     CONST GreenBlue = &HFF1164B4~& '_RGB32(17,100,180)
  185.     CONST GreenYellow = &HFFADFF2F~& ' _RGB32(173,255,47)
  186.     CONST HoneyDew = &HFFF0FFF0~& ' _RGB32(240,255,240)
  187.     CONST HotMagenta = &HFFFF1DCE~& '_RGB32(255,29,206)
  188.     CONST HotPink = &HFFFF69B4~& ' _RGB32(255,105,180)
  189.     CONST Inchworm = &HFFB2EC5D~& '_RGB32(178,236,93)
  190.     CONST IndianRed = &HFFCD5C5C~& ' _RGB32(205,92,92)
  191.     CONST Indigo = &HFF4B0082~& ' _RGB32(75,0,130)
  192.     CONST Ivory = &HFFFFFFF0~& ' _RGB32(255,255,240)
  193.     CONST JazzberryJam = &HFFCA3767~& '_RGB32(202,55,103)
  194.     CONST JungleGreen = &HFF3BB08F~& '_RGB32(59,176,143)
  195.     CONST Khaki = &HFFF0E68C~& ' _RGB32(240,230,140)
  196.     CONST LaserLemon = &HFFFEFE22~& '_RGB32(254,254,34)
  197.     CONST Lavender = &HFFE6E6FA~& ' _RGB32(230,230,250)
  198.     CONST LavenderBlush = &HFFFFF0F5~& ' _RGB32(255,240,245)
  199.     CONST LawnGreen = &HFF7CFC00~& ' _RGB32(124,252,0)
  200.     CONST LemonChiffon = &HFFFFFACD~& ' _RGB32(255,250,205)
  201.     CONST LemonYellow = &HFFFFF44F~& '_RGB32(255,244,79)
  202.     CONST LightBlue = &HFFADD8E6~& ' _RGB32(173,216,230)
  203.     CONST LightCoral = &HFFF08080~& ' _RGB32(240,128,128)
  204.     CONST LightCyan = &HFFE0FFFF~& ' _RGB32(224,255,255)
  205.     CONST LightGoldenRodYellow = &HFFFAFAD2~& ' _RGB32(250,250,210)
  206.     CONST LightGray = &HFFD3D3D3~& ' _RGB32(211,211,211)
  207.     CONST LightGreen = &HFF90EE90~& ' _RGB32(144,238,144)
  208.     CONST LightPink = &HFFFFB6C1~& ' _RGB32(255,182,193)
  209.     CONST LightSalmon = &HFFFFA07A~& ' _RGB32(255,160,122)
  210.     CONST LightSeaGreen = &HFF20B2AA~& ' _RGB32(32,178,170)
  211.     CONST LightSkyBlue = &HFF87CEFA~& ' _RGB32(135,206,250)
  212.     CONST LightSlateGray = &HFF778899~& ' _RGB32(119,136,153)
  213.     CONST LightSteelBlue = &HFFB0C4DE~& ' _RGB32(176,196,222)
  214.     CONST LightYellow = &HFFFFFFE0~& ' _RGB32(255,255,224)
  215.     CONST Lime = &HFF00FF00~& ' _RGB32(0,255,0)
  216.     CONST LimeGreen = &HFF32CD32~& ' _RGB32(50,205,50)
  217.     CONST Linen = &HFFFAF0E6~& ' _RGB32(250,240,230)
  218.     CONST MacaroniAndCheese = &HFFFFBD88~& '_RGB32(255,189,136)
  219.     CONST Magenta = &HFFFF00FF~& ' _RGB32(255,0,255)
  220.     CONST MagicMint = &HFFAAF0D1~& '_RGB32(170,240,209)
  221.     CONST Mahogany = &HFFCD4A4C~& '_RGB32(205,74,76)
  222.     CONST Maize = &HFFEDD19C~& '_RGB32(237,209,156)
  223.     CONST Manatee = &HFF979AAA~& '_RGB32(151,154,170)
  224.     CONST MangoTango = &HFFFF8243~& '_RGB32(255,130,67)
  225.     CONST Maroon = &HFF800000~& ' _RGB32(128,0,0)
  226.     CONST Mauvelous = &HFFEF98AA~& '_RGB32(239,152,170)
  227.     CONST MediumAquamarine = &HFF66CDAA~& ' _RGB32(102,205,170)
  228.     CONST MediumBlue = &HFF0000CD~& ' _RGB32(0,0,205)
  229.     CONST MediumOrchid = &HFFBA55D3~& ' _RGB32(186,85,211)
  230.     CONST MediumPurple = &HFF9370DB~& ' _RGB32(147,112,219)
  231.     CONST MediumSeaGreen = &HFF3CB371~& ' _RGB32(60,179,113)
  232.     CONST MediumSlateBlue = &HFF7B68EE~& ' _RGB32(123,104,238)
  233.     CONST MediumSpringGreen = &HFF00FA9A~& ' _RGB32(0,250,154)
  234.     CONST MediumTurquoise = &HFF48D1CC~& ' _RGB32(72,209,204)
  235.     CONST MediumVioletRed = &HFFC71585~& ' _RGB32(199,21,133)
  236.     CONST Melon = &HFFFDBCB4~& '_RGB32(253,188,180)
  237.     CONST MidnightBlue = &HFF191970~& ' _RGB32(25,25,112)
  238.     CONST MintCream = &HFFF5FFFA~& ' _RGB32(245,255,250)
  239.     CONST MistyRose = &HFFFFE4E1~& ' _RGB32(255,228,225)
  240.     CONST Moccasin = &HFFFFE4B5~& ' _RGB32(255,228,181)
  241.     CONST MountainMeadow = &HFF30BA8F~& '_RGB32(48,186,143)
  242.     CONST Mulberry = &HFFC54B8C~& '_RGB32(197,75,140)
  243.     CONST NavajoWhite = &HFFFFDEAD~& ' _RGB32(255,222,173)
  244.     CONST Navy = &HFF000080~& ' _RGB32(0,0,128)
  245.     CONST NavyBlue = &HFF1974D2~& '_RGB32(25,116,210)
  246.     CONST NeonCarrot = &HFFFFA343~& '_RGB32(255,163,67)
  247.     CONST OldLace = &HFFFDF5E6~& ' _RGB32(253,245,230)
  248.     CONST Olive = &HFF808000~& ' _RGB32(128,128,0)
  249.     CONST OliveDrab = &HFF6B8E23~& ' _RGB32(107,142,35)
  250.     CONST OliveGreen = &HFFBAB86C~& '_RGB32(186,184,108)
  251.     CONST Orange = &HFFFFA500~& ' _RGB32(255,165,0)
  252.     CONST OrangeRed = &HFFFF4500~& ' _RGB32(255,69,0)
  253.     CONST OrangeYellow = &HFFF8D568~& '_RGB32(248,213,104)
  254.     CONST Orchid = &HFFDA70D6~& ' _RGB32(218,112,214)
  255.     CONST OuterSpace = &HFF414A4C~& '_RGB32(65,74,76)
  256.     CONST OutrageousOrange = &HFFFF6E4A~& '_RGB32(255,110,74)
  257.     CONST PacificBlue = &HFF1CA9C9~& '_RGB32(28,169,201)
  258.     CONST PaleGoldenRod = &HFFEEE8AA~& ' _RGB32(238,232,170)
  259.     CONST PaleGreen = &HFF98FB98~& ' _RGB32(152,251,152)
  260.     CONST PaleTurquoise = &HFFAFEEEE~& ' _RGB32(175,238,238)
  261.     CONST PaleVioletRed = &HFFDB7093~& ' _RGB32(219,112,147)
  262.     CONST PapayaWhip = &HFFFFEFD5~& ' _RGB32(255,239,213)
  263.     CONST Peach = &HFFFFCFAB~& '_RGB32(255,207,171)
  264.     CONST PeachPuff = &HFFFFDAB9~& ' _RGB32(255,218,185)
  265.     CONST Periwinkle = &HFFC5D0E6~& '_RGB32(197,208,230)
  266.     CONST Peru = &HFFCD853F~& ' _RGB32(205,133,63)
  267.     CONST PiggyPink = &HFFFDDDE6~& '_RGB32(253,221,230)
  268.     CONST PineGreen = &HFF158078~& '_RGB32(21,128,120)
  269.     CONST Pink = &HFFFFC0CB~& ' _RGB32(255,192,203)
  270.     CONST PinkFlamingo = &HFFFC74FD~& '_RGB32(252,116,253)
  271.     CONST PinkSherbet = &HFFF78FA7~& '_RGB32(247,143,167)
  272.     CONST Plum = &HFFDDA0DD~& ' _RGB32(221,160,221)
  273.     CONST PowderBlue = &HFFB0E0E6~& ' _RGB32(176,224,230)
  274.     CONST Purple = &HFF800080~& ' _RGB32(128,0,128)
  275.     CONST PurpleHeart = &HFF7442C8~& '_RGB32(116,66,200)
  276.     CONST PurpleMountainsMajesty = &HFF9D81BA~& '_RGB32(157,129,186)
  277.     CONST PurplePizzazz = &HFFFE4EDA~& '_RGB32(254,78,218)
  278.     CONST RadicalRed = &HFFFF496C~& '_RGB32(255,73,108)
  279.     CONST RawSienna = &HFFD68A59~& '_RGB32(214,138,89)
  280.     CONST RawUmber = &HFF714B23~& '_RGB32(113,75,35)
  281.     CONST RazzleDazzleRose = &HFFFF48D0~& '_RGB32(255,72,208)
  282.     CONST Razzmatazz = &HFFE3256B~& '_RGB32(227,37,107)
  283.     CONST Red = &HFFFF0000~& ' _RGB32(255,0,0)
  284.     CONST RedOrange = &HFFFF5349~& '_RGB32(255,83,73)
  285.     CONST RedViolet = &HFFC0448F~& '_RGB32(192,68,143)
  286.     CONST RobinsEggBlue = &HFF1FCECB~& '_RGB32(31,206,203)
  287.     CONST RosyBrown = &HFFBC8F8F~& ' _RGB32(188,143,143)
  288.     CONST RoyalBlue = &HFF4169E1~& ' _RGB32(65,105,225)
  289.     CONST RoyalPurple = &HFF7851A9~& '_RGB32(120,81,169)
  290.     CONST SaddleBrown = &HFF8B4513~& ' _RGB32(139,69,19)
  291.     CONST Salmon = &HFFFA8072~& ' _RGB32(250,128,114)
  292.     CONST SandyBrown = &HFFF4A460~& ' _RGB32(244,164,96)
  293.     CONST Scarlet = &HFFFC2847~& '_RGB32(252,40,71)
  294.     CONST ScreaminGreen = &HFF76FF7A~& '_RGB32(118,255,122)
  295.     CONST SeaGreen = &HFF2E8B57~& ' _RGB32(46,139,87)
  296.     CONST SeaShell = &HFFFFF5EE~& ' _RGB32(255,245,238)
  297.     CONST Sepia = &HFFA5694F~& '_RGB32(165,105,79)
  298.     CONST Shadow = &HFF8A795D~& '_RGB32(138,121,93)
  299.     CONST Shamrock = &HFF45CEA2~& '_RGB32(69,206,162)
  300.     CONST ShockingPink = &HFFFB7EFD~& '_RGB32(251,126,253)
  301.     CONST Sienna = &HFFA0522D~& ' _RGB32(160,82,45)
  302.     CONST Silver = &HFFC0C0C0~& ' _RGB32(192,192,192)
  303.     CONST SkyBlue = &HFF87CEEB~& ' _RGB32(135,206,235)
  304.     CONST SlateBlue = &HFF6A5ACD~& ' _RGB32(106,90,205)
  305.     CONST SlateGray = &HFF708090~& ' _RGB32(112,128,144)
  306.     CONST Snow = &HFFFFFAFA~& ' _RGB32(255,250,250)
  307.     CONST SpringGreen = &HFF00FF7F~& ' _RGB32(0,255,127)
  308.     CONST SteelBlue = &HFF4682B4~& ' _RGB32(70,130,180)
  309.     CONST Sunglow = &HFFFFCF48~& '_RGB32(255,207,72)
  310.     CONST SunsetOrange = &HFFFD5E53~& '_RGB32(253,94,83)
  311.     CONST Tann = &HFFD2B48C~& ' _RGB32(210,180,140)
  312.     CONST Teal = &HFF008080~& ' _RGB32(0,128,128)
  313.     CONST TealBlue = &HFF18A7B5~& '_RGB32(24,167,181)
  314.     CONST Thistle = &HFFD8BFD8~& ' _RGB32(216,191,216)
  315.     CONST TickleMePink = &HFFFC89AC~& '_RGB32(252,137,172)
  316.     CONST Timberwolf = &HFFDBD7D2~& '_RGB32(219,215,210)
  317.     CONST Tomato = &HFFFF6347~& ' _RGB32(255,99,71)
  318.     CONST TropicalRainForest = &HFF17806D~& '_RGB32(23,128,109)
  319.     CONST Tumbleweed = &HFFDEAA88~& '_RGB32(222,170,136)
  320.     CONST Turquoise = &HFF40E0D0~& ' _RGB32(64,224,208)
  321.     CONST TurquoiseBlue = &HFF77DDE7~& '_RGB32(119,221,231)
  322.     CONST UnmellowYellow = &HFFFFFF66~& '_RGB32(255,255,102)
  323.     CONST Violet = &HFFEE82EE~& ' _RGB32(238,130,238)
  324.     CONST VioletBlue = &HFF324AB2~& '_RGB32(50,74,178)
  325.     CONST VioletRed = &HFFF75394~& '_RGB32(247,83,148)
  326.     CONST VividTangerine = &HFFFFA089~& '_RGB32(255,160,137)
  327.     CONST VividViolet = &HFF8F509D~& '_RGB32(143,80,157)
  328.     CONST Wheat = &HFFF5DEB3~& ' _RGB32(245,222,179)
  329.     CONST White = &HFFFFFFFF~& ' _RGB32(255,255,255)
  330.     CONST Whitesmoke = &HFFF5F5F5~& ' _RGB32(245,245,245)
  331.     CONST WildBlueYonder = &HFFA2ADD0~& '_RGB32(162,173,208)
  332.     CONST WildStrawberry = &HFFFF43A4~& '_RGB32(255,67,164)
  333.     CONST WildWatermelon = &HFFFC6C85~& '_RGB32(252,108,133)
  334.     CONST Wisteria = &HFFCDA4DE~& '_RGB32(205,164,222)
  335.     CONST Yellow = &HFFFFFF00~& ' _RGB32(255,255,0)
  336.     CONST YellowGreen = &HFF9ACD32~& ' _RGB32(154,205,50)
  337.     CONST YellowOrange = &HFFFFAE42~& '_RGB32(255,174,66)
  338.  
  339. TYPE Font_Type
  340.     Handle AS LONG
  341.     Background AS _UNSIGNED LONG
  342.  
  343. TYPE Border_Type
  344.  
  345.  
  346. TYPE Window_Type 'Type 100000
  347.     Defined AS INTEGER 'has this particular object been defined, or freed yet?
  348.     LinksTo AS STRING * 1024 'What this object is anchored to
  349.     LinksFrom AS STRING * 1024 'What links to this object and is anchored to it
  350.     Visible AS INTEGER 'Is it visible?
  351.     Active AS INTEGER 'Is it active
  352.     Top AS INTEGER 'X1
  353.     Left AS INTEGER 'Y1
  354.     Wide AS INTEGER 'X1 + Wide = X2
  355.     High AS INTEGER 'Y1 + High = Y1
  356.     Background AS _INTEGER64 'is it a color, or an image handle?
  357.     Border AS Border_Type
  358.  
  359.  
  360.  
  361. TYPE Button_Type 'Type 200000
  362.     Defined AS INTEGER 'has this particular object been defined, or freed yet?
  363.     Visible AS INTEGER 'Is it visible?
  364.     Active AS INTEGER 'Is it active
  365.     Top AS INTEGER 'X1
  366.     Left AS INTEGER 'Y1
  367.     Wide AS INTEGER 'X1 + Wide = X2
  368.     High AS INTEGER 'Y1 + High = Y1
  369.     Background AS _INTEGER64 'is it a color, or an image handle?
  370.     Border AS Border_Type
  371.     Font AS Font_Type
  372.  
  373.  
  374. TYPE Caption_Type 'Type 300000
  375.     Defined AS INTEGER 'has this particular object been defined, or freed yet?
  376.     LinksTo AS STRING * 1024 'What this object is anchored to
  377.     Visible AS INTEGER 'Is it visible?
  378.     Active AS INTEGER 'Is it active
  379.     Top AS INTEGER 'X1
  380.     Left AS INTEGER 'Y1
  381.     Wide AS INTEGER 'X1 + Wide = X2
  382.     High AS INTEGER 'Y1 + High = Y1
  383.     Background AS _INTEGER64 'is it a color, or an image handle?
  384.     Border AS Border_Type
  385.     '    Font AS Font_Type
  386.     FontHandle AS LONG
  387.     FontColor AS _UNSIGNED LONG
  388.     FontBackground AS _UNSIGNED LONG
  389.     Text AS STRING * 1024
  390.  
  391. DIM SHARED Windows(256) AS Window_Type
  392. DIM SHARED Captions(256) AS Caption_Type
  393. DIM SHARED WindowCount AS INTEGER, DisplayCount AS INTEGER
  394. DIM SHARED CaptionsCount AS INTEGER
  395.  
  396.  
  397. DisplayScreen = CreateScreen(1024, 720) 'This creates a screen for us.  Think of it as DisplayScreen = _NEWIMAGE(1024,720,32)
  398. SetScreen DisplayScreen 'This sets the screen we created as the active display.  Think of this as SCREEN DisplayScreen
  399.  
  400. SetBackground DisplayScreen, SkyBlue
  401. SetBorder DisplayScreen, 5, Silver
  402.  
  403. MainWindow = CreateWindow(DisplayScreen, 100, 100, 400, 400)
  404. 'Marble = _LOADIMAGE("marble.jpg", 32)
  405. SetBackground MainWindow, Violet
  406. SetBorder MainWindow, 5, Gold
  407.  
  408. MainWindowCaption = CreateCaption(MainWindow, 0, 0, 400, 30)
  409. SetBorder MainWindowCaption, 5, Gold
  410. SetText MainWindowCaption, "A Window"
  411.  
  412.  
  413.  
  414.  
  415.  
  416. UpdateScreen
  417.  
  418.  
  419.  
  420.  
  421. SUB UpdateScreen
  422.     Display = Windows(0).Defined 'the active screen when we want to draw to
  423.     DrawWindow Display
  424.     _BLEND
  425.     lf$ = Windows(Display).LinksFrom
  426.     FOR i = 1 TO LEN(lf$) STEP 4
  427.         p = _CV(LONG, MID$(lf$, i, 4))
  428.         n = p MOD 100000
  429.         SELECT CASE p \ 100000
  430.             CASE 1 'it's a whole window which we want to display
  431.                 _PUTIMAGE (Windows(n).Left, Windows(n).Top)-STEP(Windows(n).Wide, Windows(n).High), Windows(n).Defined
  432.             CASE 2 'it's a caption which we want to display
  433.                 'copy/paste from the window code here later.
  434.         END SELECT
  435.     NEXT
  436.  
  437.  
  438. SUB SetBorder (Handle AS LONG, Wide AS INTEGER, Kolor AS _UNSIGNED LONG)
  439.     num = Handle MOD 100000
  440.     SELECT CASE Handle \ 100000
  441.         CASE 1 'It's a window
  442.             Windows(num).Border.Width = Wide
  443.             Windows(num).Border.Color = Kolor
  444.             DrawWindow num 'We need to redraw the window
  445.         CASE 2 'It's a caption
  446.             Captions(num).Border.Width = Wide
  447.             Captions(num).Border.Color = Kolor
  448.             p = _CV(LONG, Captions(num).LinksTo)
  449.             SELECT CASE p \ 100000
  450.                 CASE 1: DrawWindow p
  451.             END SELECT
  452.     END SELECT
  453. SUB SetBackground (Handle AS LONG, Background AS _INTEGER64)
  454.     num = Handle MOD 100000
  455.     SELECT CASE Handle \ 100000
  456.         CASE 1 'It's a window
  457.             Windows(num).Background = Background
  458.             DrawWindow num 'We need to redraw the window
  459.         CASE 2
  460.             Captions(num).Background = Background
  461.             p = _CV(LONG, Captions(num).LinksTo)
  462.             SELECT CASE p \ 100000
  463.                 CASE 1: DrawWindow p
  464.             END SELECT
  465.     END SELECT
  466. SUB SetText (Handle AS LONG, Text$)
  467.     num = Handle MOD 100000
  468.     SELECT CASE Handle \ 100000
  469.         CASE 1 'It's a window.  Windows don't have a text property
  470.         CASE 2
  471.             Captions(num).Text = Text$
  472.             p = _CV(LONG, Captions(num).LinksTo)
  473.             SELECT CASE p \ 100000
  474.                 CASE 1: DrawWindow p
  475.             END SELECT
  476.     END SELECT
  477.  
  478.  
  479.  
  480. SUB SetScreen (Handle AS LONG)
  481.     FOR i = 1 TO 100 'only one screen can be active at a time.
  482.         Windows(i).Visible = False
  483.         Windows(i).Active = False
  484.     NEXT
  485.     num = Handle MOD 100000
  486.     Windows(0).Defined = num
  487.     Windows(num).Visible = True
  488.     Windows(num).Active = True
  489.     SCREEN Windows(num).Defined
  490.  
  491.  
  492. SUB DrawWindow (TempHandle AS LONG)
  493.     D = _DEST
  494.     Handle = TempHandle MOD 100000
  495.     w = Windows(Handle).Wide: h = Windows(Handle).High
  496.  
  497.     _DEST Windows(Handle).Defined
  498.  
  499.     SELECT CASE Windows(Handle).Background
  500.         CASE IS < 0 'it's an image handle which we want to use for the background
  501.             _PUTIMAGE (0, 0)-(w, h), Windows(Handle).Background
  502.         CASE 0 'we just want a transparent background
  503.         CASE IS > 0 'it's a color fill background
  504.             LINE (0, 0)-(w, h), Windows(Handle).Background, BF
  505.     END SELECT
  506.     FOR i = 0 TO Windows(Handle).Border.Width - 1
  507.         LINE (0 + i, 0 + i)-(w - i, h - i), Windows(Handle).Border.Color, B
  508.     NEXT
  509.     lf$ = Windows(Handle).LinksFrom
  510.     FOR i = 1 TO LEN(lf$) STEP 4
  511.         p = _CV(LONG, MID$(lf$, i, 4))
  512.         n = p MOD 100000
  513.         SELECT CASE p \ 100000
  514.             CASE 1 'it's a whole window which we want to display
  515.                 _PUTIMAGE (Windows(n).Left, Windows(n).Top)-STEP(Windows(n).Wide, Windows(n).High), Windows(n).Defined
  516.             CASE 2 'it's a caption which we want to display
  517.                 DrawCaption n
  518.             CASE ELSE
  519.         END SELECT
  520.     NEXT
  521.     _DEST D
  522.  
  523. SUB DrawCaption (n AS INTEGER)
  524.     F = _FONT
  525.     x = Captions(n).Left: y = Captions(n).Top
  526.     w = Captions(n).Wide: h = Captions(n).High
  527.     'SELECT CASE Captions(n).Background
  528.     '    CASE IS < 0 'it's an image handle which we want to use for the background
  529.     '        _PUTIMAGE (x, y)-STEP(w, h), Captions(n).Background
  530.     '    CASE 0 'we just want a transparent background
  531.     '    CASE IS > 0 'it's a color fill background
  532.     '        LINE (x, y)-STEP(w, h), Captions(n).Background, BF
  533.     'END SELECT
  534.     'FOR j = 0 TO Captions(n).Border.Width - 1
  535.     '    LINE (x + j, y + j)-(w - j, h - j), Captions(n).Border.Color, B
  536.     'NEXT
  537.     'text$ = _TRIM$(Captions(n).Text)
  538.     x = Captions(n).FontHandle
  539.     COLOR Red
  540.     LOCATE 10, 1: PRINT x, F, x = F; "Before IF"
  541.     IF x <> F THEN
  542.         LOCATE 11, 1: PRINT x, F, x = F; "In IF"
  543.         _FONT x
  544.     END IF
  545.     COLOR Black
  546.  
  547.     pw = _PRINTWIDTH(text$): ph = _FONTHEIGHT
  548.  
  549.     _PRINTSTRING (x + (w - pw) \ 2, y + (h - ph) \ 2), text$
  550.     _FONT F
  551.  
  552.  
  553. FUNCTION CreateScreen (x AS INTEGER, y AS INTEGER) 'all screens are 32-bit, no exceptions
  554.     FOR i = 1 TO 100 'first 100 windows are reserved for screens
  555.         IF Windows(i).Defined = False THEN EXIT FOR
  556.     NEXT
  557.     IF i > 100 THEN ERROR 5: PRINT "Program can not have more than 100 screens in memory at a single time!": END
  558.     Windows(i).Defined = _NEWIMAGE(x, y, 32)
  559.     CreateScreen = 100000 + i
  560.     Windows(i).Top = 0
  561.     Windows(i).Left = 0
  562.     Windows(i).Wide = x
  563.     Windows(i).High = y
  564.     Windows(i).LinksTo = ""
  565.     Windows(i).LinksFrom = ""
  566.     Windows(i).Visible = False
  567.     Windows(i).Active = False
  568.  
  569. FUNCTION CreateWindow (Anchor AS LONG, Top AS INTEGER, Left AS INTEGER, Wide AS INTEGER, High AS INTEGER)
  570.     FOR i = 101 TO WindowCount
  571.         'check for an open spot where we may have freed a past window
  572.         'windows 1 to 100 are for screens which we might create (they're basically full screen windows)
  573.         IF Windows(i).Defined = False THEN EXIT FOR
  574.     NEXT
  575.     IF i > WindowCount THEN WindowCount = i
  576.     Windows(i).Defined = _NEWIMAGE(Wide, High, 32)
  577.     Windows(i).LinksTo = _MK$(LONG, Anchor MOD 100000) 'This is what we link to
  578.     Windows(i).LinksFrom = "" 'and nothing is linking to a new window, at the moment
  579.     Windows(Anchor MOD 100000).LinksFrom = _TRIM$(Windows(Anchor MOD 100000).LinksFrom) + _MK$(LONG, 100000 + i) 'And this lets the other window know we're linked to it.
  580.     Windows(i).Top = Top
  581.     Windows(i).Left = Left
  582.     Windows(i).Wide = Wide
  583.     Windows(i).High = High
  584.     Windows(i).Visible = True 'we default to being visible and active
  585.     Windows(i).Active = True
  586.     Windows(i).Border.Width = 0
  587.     Windows(i).Border.Color = 0
  588.     CreateWindow = 100000 + i
  589.  
  590. FUNCTION CreateCaption (Anchor AS LONG, Top AS INTEGER, Left AS INTEGER, Wide AS INTEGER, High AS INTEGER)
  591.     d = _DEST
  592.     FOR i = 1 TO CaptionCount
  593.         'check for an open spot where we may have freed a past window
  594.         'windows 1 to 100 are for screens which we might create (they're basically full screen windows)
  595.         IF Captions(i).Defined = False THEN EXIT FOR
  596.     NEXT
  597.     IF i > CaptionCount THEN CaptionCount = i
  598.     Captions(i).Defined = _NEWIMAGE(Wide, High, 32)
  599.     Captions(i).LinksTo = _MK$(LONG, Anchor) 'This is what we link to
  600.     SELECT CASE Anchor \ 100000
  601.         CASE 1 'we're linking this to a window
  602.             Windows(Anchor MOD 100000).LinksFrom = _TRIM$(Windows(Anchor MOD 100000).LinksFrom) + _MK$(LONG, 200000 + i)
  603.             DrawWindow Anchor
  604.     END SELECT
  605.  
  606.     Captions(i).Top = Top
  607.     Captions(i).Left = Left
  608.     Captions(i).Wide = Wide
  609.     Captions(i).High = High
  610.     Captions(i).Visible = True 'we default to being visible and active
  611.     Captions(i).Active = True
  612.     Captions(i).Border.Width = 0
  613.     Captions(i).Border.Color = 0
  614.     Captions(i).Background = Black 'default to a solid black background
  615.     Captions(i).FontHandle = 16
  616.     Captions(i).FontColor = White
  617.     Captions(i).FontBackground = 0
  618.     Captions(i).Text = ""
  619.     CreateCaption = 200000 + i
  620.  

I've even removed any reference to the image handle which I was using as a texture for a background on the window, so what's here should copy/paste into any version of QB64 and work without any issues...

Except it doesn't. 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Anyone know what's wrong here?
« Reply #17 on: December 24, 2019, 03:56:09 pm »
Code has been cleaned up even more, and I can definitely rule out any recent changes to QB64 being at the fault for this glitch.

Code: QB64: [Select]
  1. CONST True = -1, False = 0
  2.  
  3. CONST Black = &HFF000000~& ' _RGB32(0,0,0)
  4. CONST Gold = &HFFFFD700~& ' _RGB32(255,215,0)
  5. CONST Red = &HFFFF0000~& ' _RGB32(255,0,0)
  6. CONST Silver = &HFFC0C0C0~& ' _RGB32(192,192,192)
  7. CONST SkyBlue = &HFF87CEEB~& ' _RGB32(135,206,235)
  8. CONST Violet = &HFFEE82EE~& ' _RGB32(238,130,238)
  9. CONST White = &HFFFFFFFF~&
  10.  
  11. TYPE Font_Type
  12.     Handle AS LONG
  13.     Background AS _UNSIGNED LONG
  14.  
  15. TYPE Border_Type
  16.  
  17.  
  18. TYPE Window_Type 'Type 100000
  19.     Defined AS INTEGER 'has this particular object been defined, or freed yet?
  20.     LinksTo AS STRING * 1024 'What this object is anchored to
  21.     LinksFrom AS STRING * 1024 'What links to this object and is anchored to it
  22.     Visible AS INTEGER 'Is it visible?
  23.     Active AS INTEGER 'Is it active
  24.     Top AS INTEGER 'X1
  25.     Left AS INTEGER 'Y1
  26.     Wide AS INTEGER 'X1 + Wide = X2
  27.     High AS INTEGER 'Y1 + High = Y1
  28.     Background AS _INTEGER64 'is it a color, or an image handle?
  29.     Border AS Border_Type
  30.  
  31.  
  32.  
  33. TYPE Button_Type 'Type 200000
  34.     Defined AS INTEGER 'has this particular object been defined, or freed yet?
  35.     Visible AS INTEGER 'Is it visible?
  36.     Active AS INTEGER 'Is it active
  37.     Top AS INTEGER 'X1
  38.     Left AS INTEGER 'Y1
  39.     Wide AS INTEGER 'X1 + Wide = X2
  40.     High AS INTEGER 'Y1 + High = Y1
  41.     Background AS _INTEGER64 'is it a color, or an image handle?
  42.     Border AS Border_Type
  43.     Font AS Font_Type
  44.  
  45.  
  46. TYPE Caption_Type 'Type 300000
  47.     Defined AS INTEGER 'has this particular object been defined, or freed yet?
  48.     LinksTo AS STRING * 1024 'What this object is anchored to
  49.     Visible AS INTEGER 'Is it visible?
  50.     Active AS INTEGER 'Is it active
  51.     Top AS INTEGER 'X1
  52.     Left AS INTEGER 'Y1
  53.     Wide AS INTEGER 'X1 + Wide = X2
  54.     High AS INTEGER 'Y1 + High = Y1
  55.     Background AS _INTEGER64 'is it a color, or an image handle?
  56.     Border AS Border_Type
  57.     '    Font AS Font_Type
  58.     FontHandle AS LONG
  59.     FontColor AS _UNSIGNED LONG
  60.     FontBackground AS _UNSIGNED LONG
  61.     Text AS STRING * 1024
  62.  
  63. DIM SHARED Windows(256) AS Window_Type
  64. DIM SHARED Captions(256) AS Caption_Type
  65. DIM SHARED WindowCount AS INTEGER, DisplayCount AS INTEGER
  66. DIM SHARED CaptionsCount AS INTEGER
  67.  
  68.  
  69. DisplayScreen = CreateScreen(1024, 720) 'This creates a screen for us.  Think of it as DisplayScreen = _NEWIMAGE(1024,720,32)
  70. SetScreen DisplayScreen 'This sets the screen we created as the active display.  Think of this as SCREEN DisplayScreen
  71.  
  72. SetBackground DisplayScreen, SkyBlue
  73. SetBorder DisplayScreen, 5, Silver
  74.  
  75. MainWindow = CreateWindow(DisplayScreen, 100, 100, 400, 400)
  76. 'Marble = _LOADIMAGE("marble.jpg", 32)
  77. SetBackground MainWindow, Violet
  78. SetBorder MainWindow, 5, Gold
  79.  
  80. MainWindowCaption = CreateCaption(MainWindow, 0, 0, 400, 30)
  81. SetBorder MainWindowCaption, 5, Gold
  82. SetText MainWindowCaption, "A Window"
  83.  
  84.  
  85.  
  86.  
  87.  
  88. UpdateScreen
  89.  
  90.  
  91.  
  92.  
  93. SUB UpdateScreen
  94. Display = Windows(0).Defined 'the active screen when we want to draw to
  95. DrawWindow Display
  96. lf$ = Windows(Display).LinksFrom
  97. FOR i = 1 TO LEN(lf$) STEP 4
  98.     p = _CV(LONG, MID$(lf$, i, 4))
  99.     n = p MOD 100000
  100.     SELECT CASE p \ 100000
  101.         CASE 1 'it's a whole window which we want to display
  102.             _PUTIMAGE (Windows(n).Left, Windows(n).Top)-STEP(Windows(n).Wide, Windows(n).High), Windows(n).Defined
  103.         CASE 2 'it's a caption which we want to display
  104.             'copy/paste from the window code here later.
  105.     END SELECT
  106.  
  107.  
  108. SUB SetBorder (Handle AS LONG, Wide AS INTEGER, Kolor AS _UNSIGNED LONG)
  109. num = Handle MOD 100000
  110. SELECT CASE Handle \ 100000
  111.     CASE 1 'It's a window
  112.         Windows(num).Border.Width = Wide
  113.         Windows(num).Border.Color = Kolor
  114.         DrawWindow num 'We need to redraw the window
  115.     CASE 2 'It's a caption
  116.         Captions(num).Border.Width = Wide
  117.         Captions(num).Border.Color = Kolor
  118.         p = _CV(LONG, Captions(num).LinksTo)
  119.         SELECT CASE p \ 100000
  120.             CASE 1: DrawWindow p
  121.         END SELECT
  122. SUB SetBackground (Handle AS LONG, Background AS _INTEGER64)
  123. num = Handle MOD 100000
  124. SELECT CASE Handle \ 100000
  125.     CASE 1 'It's a window
  126.         Windows(num).Background = Background
  127.         DrawWindow num 'We need to redraw the window
  128.     CASE 2
  129.         Captions(num).Background = Background
  130.         p = _CV(LONG, Captions(num).LinksTo)
  131.         SELECT CASE p \ 100000
  132.             CASE 1: DrawWindow p
  133.         END SELECT
  134. SUB SetText (Handle AS LONG, Text$)
  135. num = Handle MOD 100000
  136. SELECT CASE Handle \ 100000
  137.     CASE 1 'It's a window.  Windows don't have a text property
  138.     CASE 2
  139.         Captions(num).Text = Text$
  140.         p = _CV(LONG, Captions(num).LinksTo)
  141.         SELECT CASE p \ 100000
  142.             CASE 1: DrawWindow p
  143.         END SELECT
  144.  
  145.  
  146.  
  147. SUB SetScreen (Handle AS LONG)
  148. FOR i = 1 TO 100 'only one screen can be active at a time.
  149.     Windows(i).Visible = False
  150.     Windows(i).Active = False
  151. num = Handle MOD 100000
  152. Windows(0).Defined = num
  153. Windows(num).Visible = True
  154. Windows(num).Active = True
  155. SCREEN Windows(num).Defined
  156.  
  157.  
  158. SUB DrawWindow (TempHandle AS LONG)
  159. D = _DEST
  160. Handle = TempHandle MOD 100000
  161. w = Windows(Handle).Wide: h = Windows(Handle).High
  162.  
  163. _DEST Windows(Handle).Defined
  164.  
  165. SELECT CASE Windows(Handle).Background
  166.     CASE IS < 0 'it's an image handle which we want to use for the background
  167.         _PUTIMAGE (0, 0)-(w, h), Windows(Handle).Background
  168.     CASE 0 'we just want a transparent background
  169.     CASE IS > 0 'it's a color fill background
  170.         LINE (0, 0)-(w, h), Windows(Handle).Background, BF
  171. FOR i = 0 TO Windows(Handle).Border.Width - 1
  172.     LINE (0 + i, 0 + i)-(w - i, h - i), Windows(Handle).Border.Color, B
  173. lf$ = Windows(Handle).LinksFrom
  174. FOR i = 1 TO LEN(lf$) STEP 4
  175.     p = _CV(LONG, MID$(lf$, i, 4))
  176.     n = p MOD 100000
  177.     SELECT CASE p \ 100000
  178.         CASE 1 'it's a whole window which we want to display
  179.             _PUTIMAGE (Windows(n).Left, Windows(n).Top)-STEP(Windows(n).Wide, Windows(n).High), Windows(n).Defined
  180.         CASE 2 'it's a caption which we want to display
  181.             DrawCaption n
  182.         CASE ELSE
  183.     END SELECT
  184.  
  185. SUB DrawCaption (n AS INTEGER)
  186. F = _FONT
  187. x = Captions(n).Left: y = Captions(n).Top
  188. w = Captions(n).Wide: h = Captions(n).High
  189. 'SELECT CASE Captions(n).Background
  190. '    CASE IS < 0 'it's an image handle which we want to use for the background
  191. '        _PUTIMAGE (x, y)-STEP(w, h), Captions(n).Background
  192. '    CASE 0 'we just want a transparent background
  193. '    CASE IS > 0 'it's a color fill background
  194. '        LINE (x, y)-STEP(w, h), Captions(n).Background, BF
  195. 'END SELECT
  196. 'FOR j = 0 TO Captions(n).Border.Width - 1
  197. '    LINE (x + j, y + j)-(w - j, h - j), Captions(n).Border.Color, B
  198. 'NEXT
  199. 'text$ = _TRIM$(Captions(n).Text)
  200. x = Captions(n).FontHandle
  201. COLOR Red
  202. LOCATE 10, 1: PRINT x, F, x = F; "Before IF"
  203. IF x <> F THEN
  204.     LOCATE 11, 11: PRINT x, F, x = F; "In IF"
  205.     _FONT x
  206. COLOR Black
  207.  
  208. pw = _PRINTWIDTH(text$): ph = _FONTHEIGHT
  209.  
  210. _PRINTSTRING (x + (w - pw) \ 2, y + (h - ph) \ 2), text$
  211.  
  212.  
  213. FUNCTION CreateScreen (x AS INTEGER, y AS INTEGER) 'all screens are 32-bit, no exceptions
  214. FOR i = 1 TO 100 'first 100 windows are reserved for screens
  215.     IF Windows(i).Defined = False THEN EXIT FOR
  216. IF i > 100 THEN ERROR 5: PRINT "Program can not have more than 100 screens in memory at a single time!": END
  217. Windows(i).Defined = _NEWIMAGE(x, y, 32)
  218. CreateScreen = 100000 + i
  219. Windows(i).Top = 0
  220. Windows(i).Left = 0
  221. Windows(i).Wide = x
  222. Windows(i).High = y
  223. Windows(i).LinksTo = ""
  224. Windows(i).LinksFrom = ""
  225. Windows(i).Visible = False
  226. Windows(i).Active = False
  227.  
  228. FUNCTION CreateWindow (Anchor AS LONG, Top AS INTEGER, Left AS INTEGER, Wide AS INTEGER, High AS INTEGER)
  229. FOR i = 101 TO WindowCount
  230.     'check for an open spot where we may have freed a past window
  231.     'windows 1 to 100 are for screens which we might create (they're basically full screen windows)
  232.     IF Windows(i).Defined = False THEN EXIT FOR
  233. IF i > WindowCount THEN WindowCount = i
  234. Windows(i).Defined = _NEWIMAGE(Wide, High, 32)
  235. Windows(i).LinksTo = _MK$(LONG, Anchor MOD 100000) 'This is what we link to
  236. Windows(i).LinksFrom = "" 'and nothing is linking to a new window, at the moment
  237. Windows(Anchor MOD 100000).LinksFrom = RTRIM$(Windows(Anchor MOD 100000).LinksFrom) + _MK$(LONG, 100000 + i) 'And this lets the other window know we're linked to it.
  238. Windows(i).Top = Top
  239. Windows(i).Left = Left
  240. Windows(i).Wide = Wide
  241. Windows(i).High = High
  242. Windows(i).Visible = True 'we default to being visible and active
  243. Windows(i).Active = True
  244. Windows(i).Border.Width = 0
  245. Windows(i).Border.Color = 0
  246. CreateWindow = 100000 + i
  247.  
  248. FUNCTION CreateCaption (Anchor AS LONG, Top AS INTEGER, Left AS INTEGER, Wide AS INTEGER, High AS INTEGER)
  249. d = _DEST
  250. FOR i = 1 TO CaptionCount
  251.     'check for an open spot where we may have freed a past window
  252.     'windows 1 to 100 are for screens which we might create (they're basically full screen windows)
  253.     IF Captions(i).Defined = False THEN EXIT FOR
  254. IF i > CaptionCount THEN CaptionCount = i
  255. Captions(i).Defined = _NEWIMAGE(Wide, High, 32)
  256. Captions(i).LinksTo = _MK$(LONG, Anchor) 'This is what we link to
  257. SELECT CASE Anchor \ 100000
  258.     CASE 1 'we're linking this to a window
  259.         Windows(Anchor MOD 100000).LinksFrom = RTRIM$(Windows(Anchor MOD 100000).LinksFrom) + _MK$(LONG, 200000 + i)
  260.         DrawWindow Anchor
  261.  
  262. Captions(i).Top = Top
  263. Captions(i).Left = Left
  264. Captions(i).Wide = Wide
  265. Captions(i).High = High
  266. Captions(i).Visible = True 'we default to being visible and active
  267. Captions(i).Active = True
  268. Captions(i).Border.Width = 0
  269. Captions(i).Border.Color = 0
  270. Captions(i).Background = Black 'default to a solid black background
  271. Captions(i).FontHandle = 16
  272. Captions(i).FontColor = White
  273. Captions(i).FontBackground = 0
  274. Captions(i).Text = ""
  275. CreateCaption = 200000 + i
  276.  

Take the above, copy/paste it in any version of QB64 you want -- even all the way back to the SDL version -- and it STILL generates an error for the same _FONT statement, which we shouldn't even be calling as it's excluded in the IF Statement!

How am I the only lucky person who somehow manages to find these impossible issues with my code??  /CRY
« Last Edit: December 24, 2019, 04:14:20 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Marked as best answer by SMcNeill on December 24, 2019, 03:37:27 pm

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: Anyone know what's wrong here?
« Reply #18 on: December 24, 2019, 05:32:02 pm »
Hi Steve,
I suspect a severe program flow error in your code, which you might want to check. I've added 4 lines (91-94) to see, if the Captions().FontHandle is really initialized. And even as line 94 says END, the program runs happily until it runs into the handle error. So I was digging deeper and found the following:

1. function CreateCaption() calls sub DrawWindow() and that even before .FontHandle is set to 16
2. sub DrawWindow() calls sub DrawCaption() and runs into the error, because .FontHandle wasn't initialized yet, it enters the IF condition and so runs into the handle error.

I've to admit, that I didn't check all conditionals for the above mentioned sub calls, but obviously they are called, because the program never reaches the END in line 94.

Code: QB64: [Select]
  1. CONST True = -1, False = 0
  2.  
  3. CONST Black = &HFF000000~& ' _RGB32(0,0,0)
  4. CONST Gold = &HFFFFD700~& ' _RGB32(255,215,0)
  5. CONST Red = &HFFFF0000~& ' _RGB32(255,0,0)
  6. CONST Silver = &HFFC0C0C0~& ' _RGB32(192,192,192)
  7. CONST SkyBlue = &HFF87CEEB~& ' _RGB32(135,206,235)
  8. CONST Violet = &HFFEE82EE~& ' _RGB32(238,130,238)
  9. CONST White = &HFFFFFFFF~&
  10.  
  11. TYPE Font_Type
  12.     Handle AS LONG
  13.     Background AS _UNSIGNED LONG
  14.  
  15. TYPE Border_Type
  16.  
  17.  
  18. TYPE Window_Type 'Type 100000
  19.     Defined AS INTEGER 'has this particular object been defined, or freed yet?
  20.     LinksTo AS STRING * 1024 'What this object is anchored to
  21.     LinksFrom AS STRING * 1024 'What links to this object and is anchored to it
  22.     Visible AS INTEGER 'Is it visible?
  23.     Active AS INTEGER 'Is it active
  24.     Top AS INTEGER 'X1
  25.     Left AS INTEGER 'Y1
  26.     Wide AS INTEGER 'X1 + Wide = X2
  27.     High AS INTEGER 'Y1 + High = Y1
  28.     Background AS _INTEGER64 'is it a color, or an image handle?
  29.     Border AS Border_Type
  30.  
  31.  
  32.  
  33. TYPE Button_Type 'Type 200000
  34.     Defined AS INTEGER 'has this particular object been defined, or freed yet?
  35.     Visible AS INTEGER 'Is it visible?
  36.     Active AS INTEGER 'Is it active
  37.     Top AS INTEGER 'X1
  38.     Left AS INTEGER 'Y1
  39.     Wide AS INTEGER 'X1 + Wide = X2
  40.     High AS INTEGER 'Y1 + High = Y1
  41.     Background AS _INTEGER64 'is it a color, or an image handle?
  42.     Border AS Border_Type
  43.     Font AS Font_Type
  44.  
  45.  
  46. TYPE Caption_Type 'Type 300000
  47.     Defined AS INTEGER 'has this particular object been defined, or freed yet?
  48.     LinksTo AS STRING * 1024 'What this object is anchored to
  49.     Visible AS INTEGER 'Is it visible?
  50.     Active AS INTEGER 'Is it active
  51.     Top AS INTEGER 'X1
  52.     Left AS INTEGER 'Y1
  53.     Wide AS INTEGER 'X1 + Wide = X2
  54.     High AS INTEGER 'Y1 + High = Y1
  55.     Background AS _INTEGER64 'is it a color, or an image handle?
  56.     Border AS Border_Type
  57.     '    Font AS Font_Type
  58.     FontHandle AS LONG
  59.     FontColor AS _UNSIGNED LONG
  60.     FontBackground AS _UNSIGNED LONG
  61.     Text AS STRING * 1024
  62.  
  63. DIM SHARED Windows(256) AS Window_Type
  64. DIM SHARED Captions(256) AS Caption_Type
  65. DIM SHARED WindowCount AS INTEGER, DisplayCount AS INTEGER
  66. DIM SHARED CaptionsCount AS INTEGER
  67.  
  68.  
  69. DisplayScreen = CreateScreen(1024, 720) 'This creates a screen for us.  Think of it as DisplayScreen = _NEWIMAGE(1024,720,32)
  70. SetScreen DisplayScreen 'This sets the screen we created as the active display.  Think of this as SCREEN DisplayScreen
  71.  
  72. SetBackground DisplayScreen, SkyBlue
  73. SetBorder DisplayScreen, 5, Silver
  74.  
  75. MainWindow = CreateWindow(DisplayScreen, 100, 100, 400, 400)
  76. 'Marble = _LOADIMAGE("marble.jpg", 32)
  77. SetBackground MainWindow, Violet
  78. SetBorder MainWindow, 5, Gold
  79.  
  80. MainWindowCaption = CreateCaption(MainWindow, 0, 0, 400, 30)
  81.  
  82. _DEST 0: COLOR Red
  83. PRINT MainWindowCaption
  84. PRINT Captions(MainWindowCaption).FontHandle
  85.  
  86. SetBorder MainWindowCaption, 5, Gold
  87. SetText MainWindowCaption, "A Window"
  88.  
  89.  
  90.  
  91.  
  92.  
  93. UpdateScreen
  94.  
  95.  
  96.  
  97.  
  98. SUB UpdateScreen
  99.     Display = Windows(0).Defined 'the active screen when we want to draw to
  100.     DrawWindow Display
  101.     _BLEND
  102.     lf$ = Windows(Display).LinksFrom
  103.     FOR i = 1 TO LEN(lf$) STEP 4
  104.         p = _CV(LONG, MID$(lf$, i, 4))
  105.         n = p MOD 100000
  106.         SELECT CASE p \ 100000
  107.             CASE 1 'it's a whole window which we want to display
  108.                 _PUTIMAGE (Windows(n).Left, Windows(n).Top)-STEP(Windows(n).Wide, Windows(n).High), Windows(n).Defined
  109.             CASE 2 'it's a caption which we want to display
  110.                 'copy/paste from the window code here later.
  111.         END SELECT
  112.     NEXT
  113.  
  114.  
  115. SUB SetBorder (Handle AS LONG, Wide AS INTEGER, Kolor AS _UNSIGNED LONG)
  116.     num = Handle MOD 100000
  117.     SELECT CASE Handle \ 100000
  118.         CASE 1 'It's a window
  119.             Windows(num).Border.WIDTH = Wide
  120.             Windows(num).Border.COLOR = Kolor
  121.             DrawWindow num 'We need to redraw the window
  122.         CASE 2 'It's a caption
  123.             Captions(num).Border.WIDTH = Wide
  124.             Captions(num).Border.COLOR = Kolor
  125.             p = _CV(LONG, Captions(num).LinksTo)
  126.             SELECT CASE p \ 100000
  127.                 CASE 1: DrawWindow p
  128.             END SELECT
  129.     END SELECT
  130. SUB SetBackground (Handle AS LONG, Background AS _INTEGER64)
  131.     num = Handle MOD 100000
  132.     SELECT CASE Handle \ 100000
  133.         CASE 1 'It's a window
  134.             Windows(num).Background = Background
  135.             DrawWindow num 'We need to redraw the window
  136.         CASE 2
  137.             Captions(num).Background = Background
  138.             p = _CV(LONG, Captions(num).LinksTo)
  139.             SELECT CASE p \ 100000
  140.                 CASE 1: DrawWindow p
  141.             END SELECT
  142.     END SELECT
  143. SUB SetText (Handle AS LONG, Text$)
  144.     num = Handle MOD 100000
  145.     SELECT CASE Handle \ 100000
  146.         CASE 1 'It's a window.  Windows don't have a text property
  147.         CASE 2
  148.             Captions(num).Text = Text$
  149.             p = _CV(LONG, Captions(num).LinksTo)
  150.             SELECT CASE p \ 100000
  151.                 CASE 1: DrawWindow p
  152.             END SELECT
  153.     END SELECT
  154.  
  155.  
  156.  
  157. SUB SetScreen (Handle AS LONG)
  158.     FOR i = 1 TO 100 'only one screen can be active at a time.
  159.         Windows(i).Visible = False
  160.         Windows(i).Active = False
  161.     NEXT
  162.     num = Handle MOD 100000
  163.     Windows(0).Defined = num
  164.     Windows(num).Visible = True
  165.     Windows(num).Active = True
  166.     SCREEN Windows(num).Defined
  167.  
  168.  
  169. SUB DrawWindow (TempHandle AS LONG)
  170.     D = _DEST
  171.     Handle = TempHandle MOD 100000
  172.     w = Windows(Handle).Wide: h = Windows(Handle).High
  173.  
  174.     _DEST Windows(Handle).Defined
  175.  
  176.     SELECT CASE Windows(Handle).Background
  177.         CASE IS < 0 'it's an image handle which we want to use for the background
  178.             _PUTIMAGE (0, 0)-(w, h), Windows(Handle).Background
  179.         CASE 0 'we just want a transparent background
  180.         CASE IS > 0 'it's a color fill background
  181.             LINE (0, 0)-(w, h), Windows(Handle).Background, BF
  182.     END SELECT
  183.     FOR i = 0 TO Windows(Handle).Border.WIDTH - 1
  184.         LINE (0 + i, 0 + i)-(w - i, h - i), Windows(Handle).Border.COLOR, B
  185.     NEXT
  186.     lf$ = Windows(Handle).LinksFrom
  187.     FOR i = 1 TO LEN(lf$) STEP 4
  188.         p = _CV(LONG, MID$(lf$, i, 4))
  189.         n = p MOD 100000
  190.         SELECT CASE p \ 100000
  191.             CASE 1 'it's a whole window which we want to display
  192.                 _PUTIMAGE (Windows(n).Left, Windows(n).Top)-STEP(Windows(n).Wide, Windows(n).High), Windows(n).Defined
  193.             CASE 2 'it's a caption which we want to display
  194.                 DrawCaption n
  195.             CASE ELSE
  196.         END SELECT
  197.     NEXT
  198.     _DEST D
  199.  
  200. SUB DrawCaption (n AS INTEGER)
  201.     F = _FONT
  202.     x = Captions(n).Left: y = Captions(n).Top
  203.     w = Captions(n).Wide: h = Captions(n).High
  204.     'SELECT CASE Captions(n).Background
  205.     '    CASE IS < 0 'it's an image handle which we want to use for the background
  206.     '        _PUTIMAGE (x, y)-STEP(w, h), Captions(n).Background
  207.     '    CASE 0 'we just want a transparent background
  208.     '    CASE IS > 0 'it's a color fill background
  209.     '        LINE (x, y)-STEP(w, h), Captions(n).Background, BF
  210.     'END SELECT
  211.     'FOR j = 0 TO Captions(n).Border.Width - 1
  212.     '    LINE (x + j, y + j)-(w - j, h - j), Captions(n).Border.Color, B
  213.     'NEXT
  214.     'text$ = _TRIM$(Captions(n).Text)
  215.     x = Captions(n).FontHandle
  216.     COLOR Red
  217.     LOCATE 10, 1: PRINT x, F, x = F; "Before IF"
  218.     IF x <> F THEN
  219.         LOCATE 11, 11: PRINT x, F, x = F; "In IF"
  220.         _FONT x
  221.     END IF
  222.     COLOR Black
  223.  
  224.     pw = _PRINTWIDTH(text$): ph = _FONTHEIGHT
  225.  
  226.     _PRINTSTRING (x + (w - pw) \ 2, y + (h - ph) \ 2), text$
  227.     _FONT F
  228.  
  229.  
  230. FUNCTION CreateScreen (x AS INTEGER, y AS INTEGER) 'all screens are 32-bit, no exceptions
  231.     FOR i = 1 TO 100 'first 100 windows are reserved for screens
  232.         IF Windows(i).Defined = False THEN EXIT FOR
  233.     NEXT
  234.     IF i > 100 THEN ERROR 5: PRINT "Program can not have more than 100 screens in memory at a single time!": END
  235.     Windows(i).Defined = _NEWIMAGE(x, y, 32)
  236.     CreateScreen = 100000 + i
  237.     Windows(i).Top = 0
  238.     Windows(i).Left = 0
  239.     Windows(i).Wide = x
  240.     Windows(i).High = y
  241.     Windows(i).LinksTo = ""
  242.     Windows(i).LinksFrom = ""
  243.     Windows(i).Visible = False
  244.     Windows(i).Active = False
  245.  
  246. FUNCTION CreateWindow (Anchor AS LONG, Top AS INTEGER, Left AS INTEGER, Wide AS INTEGER, High AS INTEGER)
  247.     FOR i = 101 TO WindowCount
  248.         'check for an open spot where we may have freed a past window
  249.         'windows 1 to 100 are for screens which we might create (they're basically full screen windows)
  250.         IF Windows(i).Defined = False THEN EXIT FOR
  251.     NEXT
  252.     IF i > WindowCount THEN WindowCount = i
  253.     Windows(i).Defined = _NEWIMAGE(Wide, High, 32)
  254.     Windows(i).LinksTo = _MK$(LONG, Anchor MOD 100000) 'This is what we link to
  255.     Windows(i).LinksFrom = "" 'and nothing is linking to a new window, at the moment
  256.     Windows(Anchor MOD 100000).LinksFrom = RTRIM$(Windows(Anchor MOD 100000).LinksFrom) + _MK$(LONG, 100000 + i) 'And this lets the other window know we're linked to it.
  257.     Windows(i).Top = Top
  258.     Windows(i).Left = Left
  259.     Windows(i).Wide = Wide
  260.     Windows(i).High = High
  261.     Windows(i).Visible = True 'we default to being visible and active
  262.     Windows(i).Active = True
  263.     Windows(i).Border.WIDTH = 0
  264.     Windows(i).Border.COLOR = 0
  265.     CreateWindow = 100000 + i
  266.  
  267. FUNCTION CreateCaption (Anchor AS LONG, Top AS INTEGER, Left AS INTEGER, Wide AS INTEGER, High AS INTEGER)
  268.     d = _DEST
  269.     FOR i = 1 TO CaptionCount
  270.         'check for an open spot where we may have freed a past window
  271.         'windows 1 to 100 are for screens which we might create (they're basically full screen windows)
  272.         IF Captions(i).Defined = False THEN EXIT FOR
  273.     NEXT
  274.     IF i > CaptionCount THEN CaptionCount = i
  275.     Captions(i).Defined = _NEWIMAGE(Wide, High, 32)
  276.     Captions(i).LinksTo = _MK$(LONG, Anchor) 'This is what we link to
  277.     SELECT CASE Anchor \ 100000
  278.         CASE 1 'we're linking this to a window
  279.             Windows(Anchor MOD 100000).LinksFrom = RTRIM$(Windows(Anchor MOD 100000).LinksFrom) + _MK$(LONG, 200000 + i)
  280.             DrawWindow Anchor
  281.     END SELECT
  282.  
  283.     Captions(i).Top = Top
  284.     Captions(i).Left = Left
  285.     Captions(i).Wide = Wide
  286.     Captions(i).High = High
  287.     Captions(i).Visible = True 'we default to being visible and active
  288.     Captions(i).Active = True
  289.     Captions(i).Border.WIDTH = 0
  290.     Captions(i).Border.COLOR = 0
  291.     Captions(i).Background = Black 'default to a solid black background
  292.     Captions(i).FontHandle = 16
  293.     Captions(i).FontColor = White
  294.     Captions(i).FontBackground = 0
  295.     Captions(i).Text = ""
  296.     CreateCaption = 200000 + i
  297.  
  298.  
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Anyone know what's wrong here?
« Reply #19 on: December 24, 2019, 05:45:12 pm »
Seems like you're trying to assign a font to a different screen than the one you're on?  (after rewriting COLOR RED to COLOR &HFFFF0000 is nothing passed, and _DEST return -2 for me. Color is applied, if i use _DEST 0 before next run). Also, what is PRINT x = F on row 230? Its logical operation, 0 = false, 1 = true?

I see no reason why the program should not crash. X is zero. F is sixteen. The condition that 16 <> 0 is true. And FONT x actually calls FONT 0. But valid values for FONT are positive numbers.
The whole thing is that Captions (n).FontHandle does not contain a valid font value.
« Last Edit: December 24, 2019, 06:04:50 pm by Petr »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Anyone know what's wrong here?
« Reply #20 on: December 24, 2019, 07:32:52 pm »
Steve did you catch my note about the missing s in createCaption sub? The shared variable is CaptionsCount with an s and the variable in the sub is CaptionCount without an s. I don't know if this is causing original error but it will cause problems somewhere down the line.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Anyone know what's wrong here?
« Reply #21 on: December 24, 2019, 08:11:25 pm »
I suspect a severe program flow error in your code, which you might want to check.

Indeed!  As I was expanding on what the caption contained, I added new reset/defaults values to the end of the SUB one after another.  Once I added the font option there, the flow was off with the DrawWindow which refreshes the window for us.  A simple change to the routine order corrects this problem.

Code: QB64: [Select]
  1. FUNCTION CreateCaption (Anchor AS LONG, Top AS INTEGER, Left AS INTEGER, Wide AS INTEGER, High AS INTEGER)
  2.     d = _DEST
  3.     STATIC CaptionCount
  4.     FOR i = 1 TO CaptionCount
  5.         'check for an open spot where we may have freed a past window
  6.         'windows 1 to 100 are for screens which we might create (they're basically full screen windows)
  7.         IF Captions(i).Defined = False THEN EXIT FOR
  8.     NEXT
  9.     IF i > CaptionCount THEN CaptionCount = i
  10.     Captions(i).Defined = _NEWIMAGE(Wide, High, 32)
  11.     Captions(i).LinksTo = _MK$(LONG, Anchor) 'This is what we link to
  12.  
  13.     Captions(i).Top = Top
  14.     Captions(i).Left = Left
  15.     Captions(i).Wide = Wide
  16.     Captions(i).High = High
  17.     Captions(i).Visible = True 'we default to being visible and active
  18.     Captions(i).Active = True
  19.     Captions(i).Border.Width = 0
  20.     Captions(i).Border.Color = 0
  21.     Captions(i).Background = Black 'default to a solid black background
  22.     Captions(i).Font.Handle = 16
  23.     Captions(i).Font.Color = White
  24.     Captions(i).Font.Background = 0
  25.     Captions(i).Text = ""
  26.     SELECT CASE Anchor \ 100000
  27.         CASE 1 'we're linking this to a window
  28.             Windows(Anchor MOD 100000).LinksFrom = Windows(Anchor MOD 100000).LinksFrom + _MK$(LONG, 200000 + i)
  29.             DrawWindow Anchor 'refresh the window with the updated caption
  30.     END SELECT
  31.     CreateCaption = 200000 + i

It also explains why it would sometimes have one value and sometimes not have that same value.  When it glitches the first time, the value is 0.  The next call to DrawWindow (which, as I say, is more of a refresh Window which updates the specific window when we make a change to it) then has the proper value for Captions(n).Font.Handle and prints to the screen as we'd expect.

It's this behavior which had me utterly baffled.  I think you've found the largest problem with the code here.  Many thanks for helping to locate the issue out.  I've pounded my head on the keyboard countless times today, unable to see the glitch.  I'm glad someone with fresher eyes than mine could help track it down for me.  Many thanks!

I'd almost managed to convince myself that QB64 itself was mistranslating the code somehow, with a cross between the Array, type, and sub-type all mixed in there together.  :) 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Anyone know what's wrong here?
« Reply #22 on: December 24, 2019, 08:24:26 pm »
Seems like you're trying to assign a font to a different screen than the one you're on?  (after rewriting COLOR RED to COLOR &HFFFF0000 is nothing passed, and _DEST return -2 for me. Color is applied, if i use _DEST 0 before next run).

It does change the font for a different screen.  Each window is an independent screen, and DrawCaption draws itself on the relative screen where it's called from.

Code: [Select]
SUB DrawWindow (TempHandle AS LONG)
    D = _DEST
    Handle = TempHandle MOD 100000
    w = Windows(Handle).Wide: h = Windows(Handle).High

    _DEST Windows(Handle).Defined

^The above is what changes our _DEST to the proper screen, which isn't necessarily the visible screen.  Later, we take the various individual windows and then stack them onto the current display in a Z-order to create layering between them.  In an attempt to make certain that my program isn't going to get bogged down and slow redrawing 1000's of various windows and components each cycle, our windows are each independent screens and predrawn for us.  Only when we change something on the window, do we need to redraw that window.  Otherwise, we just leave it alone and put it as it currently exists back to the visible display. 

Quote
Also, what is PRINT x = F on row 230? Its logical operation, 0 = false, 1 = true?

(0 for false, and -1 for true.)

That was part of the issue.  The routine is called more than once, and the glitch is only there on the initial run (which called the update before the font value was set).  We got an error.  Then we clicked continued.  Then we got a successful redraw...  Which printed out results saying, "All is good!", making it hard to decipher the point at which "something isn't good". 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Anyone know what's wrong here?
« Reply #23 on: December 24, 2019, 08:33:07 pm »
Steve did you catch my note about the missing s in createCaption sub? The shared variable is CaptionsCount with an s and the variable in the sub is CaptionCount without an s. I don't know if this is causing original error but it will cause problems somewhere down the line.

I did, and I've corrected that issue as well.  Truthfully, it'd never cause us a problem, as CaptionsCount never actually needs to be used anywhere except inside of the function which creates them -- but at the same time, it's not doing what it's actually supposed to do:  Reduce the maximum number of times we have to loop to get our next available caption, rather than going all the way to the UBOUND limits in that loop.

Code: [Select]
    FOR i = 1 TO CaptionCount
        'check for an open spot where we may have freed a past caption
        IF Captions(i).Defined = False THEN EXIT FOR
    NEXT
    IF i > CaptionCount THEN CaptionCount = i

I've swapped them all over from SHARED variables to STATIC ones now, which are local only to the sub which they're relevant to.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Anyone know what's wrong here? (Rho knows!)
« Reply #24 on: December 24, 2019, 11:05:32 pm »
if its figured out all good, but does Rho's answer explain why the value was changing mid routine? showing 0 before the error line but 16 after? I get the program flow issue, but this was literally  printing the variable before the  _FONT line and getting a 0 then printing the variable after the _FONT line and getting a 16.

Just curious. :)
Granted after becoming radioactive I only have a half-life!

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: Anyone know what's wrong here? (Rho knows!)
« Reply #25 on: December 25, 2019, 05:37:41 am »
You're welcome Steve,
just see it as my Christmas present for you :), Enjoy the holiday(s).
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Anyone know what's wrong here? (Rho knows!)
« Reply #26 on: December 25, 2019, 02:19:16 pm »
Hi  Merry Christmas
and I see here an hard session of debugging!

But stop now it is time to eat and drink and dance and smile with family and friends...
Happy holidays and more over Happy life wonderful QB64 community...

PS be afraid  to wish because wishes become reality  ;-)
Programming isn't difficult, only it's  consuming time and coffee