Qbasicnews.com

Full Version: program out of memory?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
after adding the savegame feature into my lastest greatest, im getting an error when compiling (qb45). the program is quite big (1800 lines)... and although im not the greatest programmer, i tend to keep thing very clean and efficient. after crawling thru the code over the past few days, ive managed to clean a few things up (and even rewrite some stuff). however i can't get rid of this error.

if i compile manually at the command line w/o the debugging, it compiles fine and says i have 3200 bytes free. but when i run the program and preform a few clicks here and there, then save... it crashes. if i remove this one small condition (an 8 line if, elseif statement) everything works perfect.

Code:
IF shoptype$ = "s" THEN
       button 45, 170, 20, STR$(FuelQty%), 0, 15, 0
       button 60, 170, 20, STR$(FoodQty%), 0, 15, 0
       button 75, 170, 20, STR$(RockQty%), 0, 15, 0
       button 90, 170, 20, STR$(AmmoQty%), 0, 15, 0
ELSEIF shoptype$ = "m" THEN
       button 45, 170, 20, STR$(ArmorQty%), 0, 15, 0
       button 60, 170, 20, STR$(PowerQty%), 0, 15, 0
       button 75, 170, 20, STR$(SheildQty%), 0, 15, 0
END IF

i cant for the life of me figure this out. so....
if anyone has some suggestions or work arounds for this, please lemme know. i want to finish this damn game already! Smile
thanx in advance guys.
the program compiles fine and the executable seems to get created okay but you're getting an "Out of memory" error when you *run* your program. Do I have that right? Just a shot in the dark, but it seems that you're calling some sort of "button" subroutine and it may be asking for memory that your program can't get to. Does that subroutine use a relatively large array? Are you using '$DYNAMIC ? (That sometimes fixes things even when large arrays aren't used.)
lemme check that... i forgot the $dynamic tag
nope, didnt work...

okay here are the errors im getting.
[Image: e1.gif]

the top one i get when i try to use the '$DYNAMIC

the middle is the text output when i compile the game... no errors at all

the third is the error i get in game, UNLESS i remove the code i previously posted. it doesnt make sense?

the button SUB is simple, but it does stack an array to keep track of the 'hit spots' or clickable areas. but they work perfect and there is no need to change em.

still stumped :|
Could you post your 'button' routine? (if it's not too big Smile) Might help uncover something.

- Dav
.
here is the button SUB

Code:
SUB button (winY%, winX%, length%, label$, bcolor%, tcolor%, mode%)
' adjust the button length and position alittle (graphics)
length% = length% + 4
winY% = winY% + 1

' if the button is a clickable one, not just a txtbox
IF mode% = 1 THEN
    buttonstack% = buttonstack% + 1
    xbutton%(buttonstack%) = winX%
    ybutton%(buttonstack%) = winY%
    wbutton%(buttonstack%) = length%
    clickto$(buttonstack%) = label$
END IF

'if the button background is transparent
    IF bcolor% = -1 THEN
            LINE (winX%, winY%)-(winX% + length%, winY% + 8), bcolor%, B
            font label$, winX% + 3, winY%, tcolor%

'if there is NO box around the button... just text (and possibly clickable)
    ELSEIF bcolor% = -2 THEN
            font label$, winX% + 3, winY%, tcolor%

'if none of the above, and its not a 'special' navigation button
    ELSEIF bcolor% <> -2 AND bcolor% <> -3 THEN
            LINE (winX%, winY%)-(winX% + length%, winY% + 8), bcolor%, BF
            LINE (winX%, winY%)-(winX% + length%, winY% + 8), 21, B
            LINE (winX%, winY%)-(winX% + length%, winY%), 26
            LINE (winX%, winY%)-(winX%, winY% + 8), 26
            font label$, winX% + 3, winY%, tcolor%
' if it IS a special navigation button    
            ELSEIF bcolor% = -3 THEN
            CIRCLE (winX% + 4, winY% + 4), 1, 53
    END IF
END SUB

here is how i detect the hotspots for the buttons

Code:
DO
      keypress$ = INKEY$
      IF keypress$ = CHR$(27) THEN END
      MouseDriver 3, bx%, CX%, DX%, lb%, rb%, 0
      xmouse% = INT(CX% / 2) - 1
      ymouse% = DX% - 1
      IF holdbutton% = 1 AND lb% = 0 THEN holdbutton% = 0

'check for a button press
'if you hold the button down, it only registers one click  
IF holdbutton% = 0 AND lb% = -1 THEN
        holdbutton% = 1

'check the array of buttons that are hot
        FOR i = 1 TO buttonstack%
          IF xmouse% > xbutton%(i) AND xmouse% < (xbutton%(i) + wbutton%(i)) AND ymouse% > ybutton%(i) AND ymouse% < (ybutton%(i) + 10) THEN
'hide the mouse          
            MouseDriver 2, bx%, CX%, DX%, lb%, rb%, 0
'assign the action$ the value of the button clicked.
            action$ = clickto$(i)
'goto where the button does something
            GOTO actionbutton
            EXIT FOR
          END IF
        NEXT i
    END IF
LOOP


actionbutton:
    IF action$ = "new game" THEN
        sensors
        GOTO introscreen
    END IF.................... etc

i commented it to give u an idea of what im trying to do.
each time i change screens, i reset the buttonstack% to 0. this prevents you from clicking buttons that arent in the 'active' menu.
to your button subroutine? Is it in a common block or is it an otherwise shared variable?
shared, should it be common?
DIM SHARED as long as it's shared somehow. I don't see anything obvious right now about that subroutine that would cause an out of memory error. Unless I missed something, there's not even one DIM statement in it. (It's hard to believe that you're so close to memory limits that introducing a few more scalar variables in that subroutine would overflow memory.)
Pages: 1 2