Picture allocation trouble
Author |
Message |
shoobyman
|
Posted: Mon Jan 08, 2007 5:24 pm Post subject: Picture allocation trouble |
|
|
code: | View.Set ("offscreenonly")
colourback (black)
var eneship : flexible array 1 .. 360 of int
var ship1 : array 1 .. 360 of int
for i : 1 .. 360
View.Update
cls
locate (1, 1)
locate ((maxrow div 2) - 1, (maxcol div 2) - 4)
Text.Colour (0)
put "LOADING"
drawfillbox (10, (maxy div 2) + 10, ((i + 10) + 20), (maxy div 2) + 20, 42)
ship1 (i) := Pic.FileNew ("ship.bmp")
ship1 (i) := Pic.Rotate (ship1 (i), i, 33, 33)
eneship (i) := Pic.FileNew ("enemyship.bmp")
eneship (i) := Pic.Rotate (eneship (i), i, 33, 33)
end for
|
You may need to have 2 pictures called ship.bmp and enemyship.bmp in order to see my error. When it runs, it gives an error that the picture was not successfully created. However, if i get rid of the "eneship" or "ship1" stuff, it works fine. I think this is because it has no room to allocate new pictures, but it hasn't exceeded 1000 pictures yet. Anyone know what my problem is? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
CodeMonkey2000
|
Posted: Mon Jan 08, 2007 5:33 pm Post subject: Re: Picture allocation trouble |
|
|
try something like this:
code: | View.Set ("offscreenonly")
colourback (black)
var eneship : flexible array 1 .. 360 of int
var ship1 : array 1 .. 360 of int
var m, b : int
m := Pic.FileNew ("ship.bmp")
b := Pic.FileNew ("enemyship.bmp")
for i : 1 .. 360
View.Update
cls
locate (1, 1)
locate ((maxrow div 2) - 1, (maxcol div 2) - 4)
Text.Colour (0)
put "LOADING"
drawfillbox (10, (maxy div 2) + 10, ((i + 10) + 20), (maxy div 2) + 20, 42)
ship1 (i) := Pic.Rotate (m, i, 33, 33)
eneship (i) := Pic.Rotate (b, i, 33, 33)
end for
|
you kept allocating memory for the same picture, so just allocate it once and use that like a reference. |
|
|
|
|
|
Clayton
|
Posted: Mon Jan 08, 2007 5:46 pm Post subject: Re: Picture allocation trouble |
|
|
are you getting the error from the Pic.FileNew() or the Pic.Rotate()? highlight the line where you get the error, or post up the pictures with the code. |
|
|
|
|
|
ericfourfour
|
Posted: Mon Jan 08, 2007 8:40 pm Post subject: Re: Picture allocation trouble |
|
|
Well let's isolate a bit of code:
What you need to understand is that Pic.FileNew and Pic.Rotate bot allocate memory for one picture. In the for loop you are allocating memory for 4 pictures each iteration. If there are 360 iterations that means at the end of your program you will have 360 * 4 = 1440 (+ 2 at the beginning) pictures. Since Turing's preset maximum is 1000 it is impossible for your code to finish. I would recommend loading around 36 images instead (one for every ten degrees). Also, you should look into the procedure, Pic.Free. |
|
|
|
|
|
|
|