![]() |
Forum Index : Microcontroller and PC projects : CMM2 Sprites Not enough Heap Memory
Author | Message | ||||
Chopperp![]() Guru ![]() Joined: 03/01/2018 Location: AustraliaPosts: 1097 |
Hi Just started playing around with sprites for the first time hoping to get a sprite graph grid overlay which then could be hidden, the graph moved back 5 minutes when reaching the end (BLIT) & the grid reapplied. I looked at the Mouse example & made up a couple of test sprites the same way. I tried various things without much success & then I ran into getting the error "Error in line XX: Not enough heap memory" after a number of iterations of the test loop : OK. I played around a bit with the size of the sprites etc & eventually seemed to get rid of the error. A bit later on, I happen to notice that I accidently left a comma "," out of the Sprite header. I had 242 1, 260 instead of 242, 1, 260. Re-inserting the "," brought back the error. Anyway, below is a test program and two zipped sprite files, one with a normal header which gives the Heap Memory error & the other with the first "," omitted which doesn't. The latter sprite file sometimes upset the program (as it should), but most of the times it runs OK. The 2 sprite files are below. Graph_01A.zip As shown, the program will load the normal sprite file. Comment out sp1$ in the second line & uncomment the other sp1$ in the third line. cls COLOUR RGB(GREEN) 'set text colour sp1$ = "Graph_01.spr" 'parameters 242, 1, 260 'sp1$ = "Graph_01A.spr" 'parameters 242 1, 260 NOTE, no comma after 242 print @(10, 20) "Sprite File = " sp1$ box 1, 1, mm.hres - 1, mm.vres - 15 do print @(10,40) "Iterations = " str$(ctr) sprite load sp1$, 1 'load the graph sprite sprite load sp1$, 2 'load graph sprite as #2 sprite load sp1$, 3 'load graph sprite as #3 sprite show 1, 30, 200, 1 'display the sprite sprite show 2, 270,200, 1 'display the sprite displaced 240 pixels sprite show 3, 510,200, 1 'display the sprite displaced another 240 pix pause 50 sprite hide all pause 50 SPRITE CLOSE ALL ctr = ctr + 1 loop My main question is "Why is the heap memory error occurring?". The manual says that the sprite memory is cleared when the sprites are closed. (I could be doing something stupid) BTW, I'm playing around with the Ghost demo & may be what I want. Thanks Brian ChopperP |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
It is a bug (memory leak) in LOAD SPRITE. Will be fixed in next beta. However, the ghost approach is definitely the correct one for your application Edited 2021-02-18 19:56 by matherp |
||||
Chopperp![]() Guru ![]() Joined: 03/01/2018 Location: AustraliaPosts: 1097 |
Thanks Peter ChopperP |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1132 |
Could you use a 12 bit mode and put the grid, and any other overlay stuff, on page 1 and do your scrolling graph on page 0? Visit Vegipete's *Mite Library for cool programs. |
||||
Chopperp![]() Guru ![]() Joined: 03/01/2018 Location: AustraliaPosts: 1097 |
Hi vegipete, I'm having some success in 12 bit mode, but I'm using mode 1 (800 x 600) & getting tearing during page swapping. Will try another monitor in a while. Still not really sure what I'm doing yet ![]() ChopperP |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1132 |
I had a quick play and created the following. There does seem to be the occasional flicker. Not sure why. The first version works by clearing the page and redrawing the entire plot. SCROLL and BLIT are a problem though in the second version. mode 1,12 page write 1:cls page write 0:cls ' draw grid and stuff on page 0, which is behind for x = 0 to MM.HRES step 25 line x,0,x,MM.VRES,1,&hF404040 next x for x = 0 to MM.VRES step 25 line 0,x,MM.HRES,x,1,&hF404040 next x ' add some text, background colour = -1 so grid is not erased behind text text 100, 50,"A slowly changing signal",,2,,rgb(red),-1 text 100, 75,"A medium signal",,2,,rgb(green),-1 text 100,100,"A faster signal",,2,,rgb(blue),-1 text MM.HRES/2,MM.VRES/2+10,"Press any key to quit...","CM",,,,-1 ' draw chart on page 2, which will get copied to page 1 later page write 2 t = 0 do cls ps1 = PlotFunc(1,t) ps2 = PlotFunc(1.7,t) ps3 = PlotFunc(3,t) for i = 5 to MM.HRES step 5 pe1 = PlotFunc(1,i+t) pe2 = PlotFunc(1.7,i+t) pe3 = PlotFunc(3,i+t) line i-5,ps1,i,pe1,1,rgb(red) line i-5,ps2,i,pe2,1,rgb(green) line i-5,ps3,i,pe3,1,rgb(blue) ps1 = pe1 ps2 = pe2 ps3 = pe3 next i t = t + 5 page copy 2,1,B ' copy to plot to page 1, the top page loop until inkey$ <> "" function PlotFunc(pitch,x) PlotFunc = MM.VRES/2 + MM.VRES/2 * .95 * sin(pitch * x / 500) end function However, I cannot get this to work with PAGE SCROLL or BLIT. The result is terrible! There seems to be something wrong with both SCROLL and BLIT in 12 bit mode. In the following, if you change the first line to "mode 1,8" and change line 40 to "page copy 2,0,B", then it scrolls fine (although the underlay is lost.) mode 1,12 page write 1:cls page write 0:cls ' draw grid and stuff on page 0, which is behind for x = 0 to MM.HRES step 25 line x,0,x,MM.VRES,1,&hF404040 next x for x = 0 to MM.VRES step 25 line 0,x,MM.HRES,x,1,&hF404040 next x ' add some text, background colour = -1 so grid is not erased behind text text 100, 50,"A slowly changing signal",,2,,rgb(red),-1 text 100, 75,"A medium signal",,2,,rgb(green),-1 text 100,100,"A faster signal",,2,,rgb(blue),-1 text MM.HRES/2,MM.VRES/2+10,"Press any key to quit...","CM",,,,-1 ' draw chart on page 2, which will get copied to page 1 later page write 2 : cls t = MM.HRES ps1 = PlotFunc(1 ,t) ' compute starting y-coord of plot segments ps2 = PlotFunc(1.7,t) ps3 = PlotFunc(3 ,t) do blit 5,0,0,0,MM.HRES-5,MM.VRES : box MM.HRES-5,0,5,MM.VRES,0,,0 ' page scroll 2,-5,0,0 ' scroll page 2 left 5 pixels, fill in with black t = t + 5 pe1 = PlotFunc(1 ,t) ' compute ending y-coord of plot segments pe2 = PlotFunc(1.7,t) pe3 = PlotFunc(3 ,t) line MM.HRES-5,ps1,MM.HRES,pe1,1,rgb(red) line MM.HRES-5,ps2,MM.HRES,pe2,1,rgb(green) line MM.HRES-5,ps3,MM.HRES,pe3,1,rgb(blue) ps1 = pe1 ' start next segment from end of previous ps2 = pe2 ps3 = pe3 page copy 2,1,B ' copy to plot to page 1, the top page loop until inkey$ <> "" function PlotFunc(pitch,x) PlotFunc = MM.VRES/2 + MM.VRES/2 * .95 * sin(pitch * x / 500) end function Visit Vegipete's *Mite Library for cool programs. |
||||
Chopperp![]() Guru ![]() Joined: 03/01/2018 Location: AustraliaPosts: 1097 |
Gee thanks vegipete. A few interesting concepts there. I'm getting similar results as you for the second one. (Not quite so bad if you put a PAUSE 1000 into the loop) My graph starts on the LHS, & starts BLITing every 5 mins after 6 hrs & then resets at midnight. Basically I currently use dots (pixels) for the grids (as shown in the SPRITE files) for every 5 mins & blank them out with black pixels just prior to a BLIT & then redraw the pixels. (black background). This works OK but does leave missing pixel in the graph line if the graph line happens to fall on a pixel at the time of BLITing. This is not a real concern but I was hoping that using sprites would be a better way to go. Brian Edit. Changing monitors didn't make any difference Edited 2021-02-19 10:59 by Chopperp ChopperP |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
You are just exceeding the bandwidth of the SDRAM - just displaying 2 planes @ 16 bit each = 160Mbytes/second + then you are reading and writing the whole video memory with the scroll and/or blit. Try in a lower resolution or if you really need the high resolution then you should consider a pixel array. I've got a hack version of the CMM2 with faster memory that I'm playing with and your code works fine on that see the video so there is nothing wrong with the firmware just you have hit a H/W limit |
||||
Chopperp![]() Guru ![]() Joined: 03/01/2018 Location: AustraliaPosts: 1097 |
Thanks Peter for that diagnostic. The video looked good.(CMM2 on steroids. Wow Some things to ponder. Brian ChopperP |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1132 |
Perhaps you've made it too easy for us to crush the system. ![]() I made a version of the test program that did a CLS and redrew the entire three plots. That worked OK but obviously required knowing/storing a screen's worth of data points. The hope was that changing to a SCROLL or a BLIT would only require knowing the most recent data point and the new one. But why is the SCROLL or BLIT interfering with the screen draw, especially since it involves a non-display page? Does the processor get stuck waiting for SCROLL or BLIT to complete, at the cost of loss of video timing/generation? It does work nice and clean in MODE 2,12 (640x400) and MODE 8,12 (640x480), although MODE 8 is a bunch slower. Modes 3 & 6 are nutso fast. Visit Vegipete's *Mite Library for cool programs. |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |