Speed issues on vector map drawing

Discussion in 'Questions (Windows Mobile)' started by junglejet, Jan 26, 2009.

  1. junglejet

    junglejet Active Member Licensed User

    Hello again,

    my application draws a vector map from coordinates text files directly by "disk" read. A map load or refresh is very slow. Has anybody experience with this? Is it the fileread function or the graphics display that is so slow? I draw with the standard form.xxx commands. No complex drawing, just a few lines. Would keeping the coordinates in memory (array) speed up a redraw?

  2. Cableguy

    Cableguy Expert Licensed User

    I assume this is on a device....
    Can you redraw ONLY the new lines instaed of redrawing all?
    Add a flag to the arrayitem in order to know if the line has been already drawn...
    This may speed up things...
    Also a well placed doevents keyword can do wonders when drawing on screen...
  3. klaus

    klaus Expert Licensed User

    Hi junglejet,

    A few questions:
    - How many lines do you have?
    - How do you read and draw, read one set of coordinates and draw a line or read all coordinates and draw all lines after reading?
    - When you refresh the map, do you load the coordinates from the file, in that case you should better have them in an array?
    - When do you refresh the screen?
    - Do have some code that we could look at and compare? This would be easyer for us to give you a correct answer.

    To determine what part of your code takes more time you can put time variables in several parts of the code and display them at the end.

    You could also have a look at this for comparison: http://www.basic4ppc.com/forum/share-your-creations/3674-scaled-maps.html

    Best regards.
  4. junglejet

    junglejet Active Member Licensed User

    Yes, this is on a device.

    This is a vector map file where the coordinates are stored inside a text file as ASCII and then loaded line by line, converted to screen coordinates and drawn by the Line command. The calculation is simple. I don't have the code at hand here. But it is as simple as that.

    My question is:

    - is reading a file a known slow exercise on a PDA (this is the same on all PDAs I tested it), maybe because it is read from Flash and not from RAM?


    - is drawing lines with a PDA form.line command a known slow exercise, maybe because of clipping etc.

    I know I can load the file to an array or I may be able to speed up the graphics by additional means, but I just wanted to hear suggestions. What I can't do is avoiding loading the entire file after zoom or pan.

    Klaus, I couldn't check your samples yet, I will do that later.

    Thanks for all your help
  5. Erel

    Erel Administrator Staff Member Licensed User

    How are you loading and parsing the file? What is its size?
    How many lines are you drawing?

    Drawing with ImageLib will be faster as it doesn't refreshes the form after each drawing.
  6. junglejet

    junglejet Active Member Licensed User

    I have now loaded the coordinates to an array and the drawing speed is still very low. Especially clipping is very slow. Avoiding to draw outside the visible screen gains some speed.

    Then after your advise I converted a polygon drawing routine to imagelib. Here it is:
    Sub drawpoly1 (x,y,color)
    '               points(0).X = x-1-vga2
    '               points(0).Y = y-1-vga2
    '            points(1).X = x+1+vga2
    '            points(1).Y = y-1-vga2
    '            points(2).X = x+1+vga2
    '            points(2).Y = y+1+vga2
    '            points(3).X = x-1-vga2
    '            points(3).Y = y+1+vga2
    '            Form1.Polygon(points(),0,4,color)
                   rect1.X = x-1-vga2
                   rect1.Y = y-
                   rect1.width = 
    End Sub
    IDE and Windows EXE compilation are fine. Once I start it as a compiled EXE on the device it halts with Error occurred in sub _main_drawpoly1

    EDIT: pen1 and drawer1 are newed in APP_START
    EDIT: when I take away the pen1.color= line the error persists
    EDIT: the same occurs with drawer1.DrawLine...
    EDIT: the same occurs when I take away the refresh command

    Any ideas?
    Last edited: Feb 8, 2009
  7. junglejet

    junglejet Active Member Licensed User

    I have found that putting any drawer.xxxx call into a sub causes the error. When I put a drawer.xxx into App_Start the application works well.

    To remember: only on the device - on the desktop everything is ok
  8. agraham

    agraham Expert Licensed User

    PLEASE, anybody reading this as well as the OP. If you have a problem then please, please, please post a real code example that we can run to see if we can reproduce your problem. If we have to take descriptions and code fragments and try to reimplement forms and controls it takes a lot of time and effort and we won't necessarily replicate your problem because you may be assuming things that we don't know about and ignoring things that you think are trivial but are actually important to the problem.

    Post some example code and then we can take a proper look at the problem!
  9. klaus

    klaus Expert Licensed User

    What library are you using, the ImageLib or the ImageLibEx?

    I have no problems using a drawer in a Sub with the ImageLib !

    If you use the ImageLibEx you should add Sip(False) in the App_Start routine.

    I fully agree with agraham, it is boring to need to make our own test programs to try to find out what the problem could be. With your code we can test it and see what happens and then give you an answer.

    Best regards.
    Last edited: Feb 10, 2009
  10. Cableguy

    Cableguy Expert Licensed User

    I do believe that a "good practice" rules should be presented in a sticky post, and be followed by new posters...
    Yes, if you want us to help you, then you must give us all the relevant info, as trivial as it may seem...
    As Agraham and Klaus stated, we may not even be close to replicate your problem, unless you provide a "problematic" example file...

    So ...

  11. junglejet

    junglejet Active Member Licensed User

    Thank you, but I am a bit uneasy with your three comments, some of them in capital letters.

    I use the imagelib and NOT imagelibex. In addition I had added SIP(false) already to APP_START.

    My application code is commercial and under NDA by the company it is written for, and over 1400 lines, so I will not post it here. Cutting the relevant parts is the same pain for me as I need to build up a complete new application as you need to do. I am not expecting anybody to do that for me, though.

    I do application programming since 30 years in various languages, mainly Delphi, and partly for a living. My experience is that usually somebody had seen a systematic error before or the develeoper with source code in hands can easily check for it. If both is not the case here I am not expecting anything more.

    I must say that in the short time I use B4PPC I have run into problems that I have not expected so. I have applications that work on the IDE PCs, but not other PCs; that work on IDE but not PDA; that work on compiled Windows but not compiled PDA and so on. This is certainly not so much related to the B4PPC shell but to he underlying .net core, but asking for help should be allowed.

    I keep you posted about the outcome. Usually it kicks in after a good rest and a bottle of wine...

  12. klaus

    klaus Expert Licensed User

    Does the attached program work on your computer.

    It runs and compiles without any problem on mine, desktop and Qtek9090.

    Best regards.
  13. junglejet

    junglejet Active Member Licensed User

    Hi Klaus,

    thanks for your kind effort. I had done just the same in the meantime and the application runs well. :sign0060:

    The problem seems to be hidden somewhere inside the complexity of the application, most likely with the high number of DLLs merged (it uses GPSDriver, Hardware, Formlib, HTTP, BinaryFile, Bitwise, Door, Colordialog, ControlsEx).

    It acts as a transponder and sends the GPS data via HTTP request to a server and receives other GPS data that are displayed on a vector map, that you get the impression. Fast vector drawing is necessary as this will be a worldwide distibution with aviation data.
    SBS Forum :: View topic - Beta testing for new Mobile-S PDA smartphone viewer
    The vector data files are small and for the current area only, so should not be a big deal, I thought.

    I am underway to cut down the source file into smaller pieces and keep you posted. The error I get appears on two HTC devices of different type.

    Last edited: Feb 10, 2009
  14. klaus

    klaus Expert Licensed User

    What's the exact text of the error you get on the device ?
    What values can take x,y and vga2 ?
    The strange thing is that the compiler doesn't generate any error.

    I have a program with a lot of libraries too, not the same as yours (ImageLib, FormLib, dzImageLib,Door,ControlsEx, Hardware, RichTextBox, ColorDialog and BinaryFile), and 3750 lines of code, without problems.

    The only problems I had on devices were with wrong init files or values inside these files.

    Best regards.
    Last edited: Feb 10, 2009
  15. junglejet

    junglejet Active Member Licensed User

    Here is another sub that crashes. The screenshot is from this routine. It is the caller of the sub DrawPoly1 from above. You can see that x,y are within the screen. VGA2 is 2 for VGA screens. To me nothing spectacular. Probably not that more time before the weekend to tear down the source.

    For j=0 To i
    If (x>0AND (x<formwidth) AND (y>0AND (y<formheight) Then
    Select wptcolor.Item(j)
    Case 32 
    Case 31
    Case 30
    Case Else
             End Select                  
    If cbwptid.Checked Then form1.DrawString(wptid.Item(j),7,x+2,y-4,x+100,y+20,cGray)
    End If

    Attached Files:

  16. agraham

    agraham Expert Licensed User

    The nature of .NET means that the number of dlls is very unlikely to cause want unwanted interactions. Due to the very strict typing and lack of programmer accessible memory pointers complexity problems like we used to get with C/C++ applications just don't arise in .NET apps due to the strict type segregation.
    One thing to get used to is that .NET apps do not "crash" in the same sense as unmanaged apps can crash. I have not yet seen a true crash in a .NET app. However the .NET way of handling errors is to throw an exception. Any error, from access outside an arrray boundary to a file not found, will throw an exception. The old practice of returning an error value is used very infrequently in .NET. This is why ErrorLabel is provided to catch exceptions in Basic4ppc. If an ErrorLabel is not used in a Sub you get the "Continue Yes/No" message box. Unfortunately, as standard, the code in an ErrorLabel block cannot determine the cause of the exception. However using my Exceptions library would let you access the exception type and message programmatically to deal with yourself.
  17. Erel

    Erel Administrator Staff Member Licensed User

    If you can, try to run your source code from the device IDE. That way you will see where exactly your program fails.

    It is strange that there is no error description at all. Is it possible that the device ran out of memory? Or maybe a stack overflow?
  18. junglejet

    junglejet Active Member Licensed User

    I was able to track the error further down.

    The exception is a <see thumbnail>.

    Originally: it appears always. When I replace
    in the sub the error does not appear in normal screen mode first. As soon as I switch to Fullscreen mode (latest when I switch back) first the polygons I draw disappear and then the error comes up again. So there is still something wrong, but it seems to be related to the pen. I feel uncomfortable to repeat pen1.new() on every call to the subroutine anyhow. My :confused: tells me to do a pen1.dispose everytime, but then an immediate error appears asking for a non-referenced object. I assume there is a garbage collector that takes care?

    When I strip down the program to a few lines as attached, the error does not appear.

    On the device IDE the error does not seem to appear, though the polygons disappear after a Fullscreen(true). But this runs in non-VGA mode, though on a VGA device.
  19. agraham

    agraham Expert Licensed User

    I wonder if it is in fact the the Drawer, not the Pen. I can't really see how Pen.New1(color) could fail, as long as there is a Pen object there, but Drawer.New1(Form, Forelayer) saves a GDI Graphics object to use when drawing on the form. I wonder if switching to Fullscreen invalidates this Graphics. You could try another New1 on Drawer1 after the switch to test this.

    You would need to use AddObject("pen1", "Pen") to add back a disposed Pen to reuse it. The same applies to reuse any disposed object or control.

    Yes, quite a sophisticated one, worth reading about if (like me) you are interested in systems engineering. In fact the techincal detail of the implementation of the whole .NET Framework is an interesting example of an excellent total software system design.

    The IDE is more forgiving than the optimising compiler ... It will as the IDE is a .NET 1.0 app and a VGA device always runs them with a virtual QVGA screen. This is not true for a .NET 2.0 app which is what optimised compilation generates, they are assumed to be VGA aware and are run as normal apps.
  20. junglejet

    junglejet Active Member Licensed User

    Thanks, Andrew, for the nice explanation. This certainly helps to understand the concept. I am confident we will track the cause down.

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice