Page 1 of 2

LoadFont not allowed between Drawing Start/Stop

Posted: Wed Oct 19, 2005 8:57 pm
by PB&J Lover
The example in the help file is this:

Code: Select all

If PrintRequester()

  If StartPrinting("PureBasic Test")
  
    If StartDrawing(PrinterOutput())

      DrawingFont(LoadFont(0, "Arial", 30))
  
      Locate(100, 100) : DrawText("PureBasic Printer Test")
      
      DrawingFont(LoadFont(0, "Arial", 100))
      
      Locate(100, 400) : DrawText("PureBasic Printer Test 2")
    
      If LoadImage(0, "Data\PureBasic.bmp")
        DrawImage(ImageID(), 200, 600)
      Else
        MessageRequester("","2",0)
      EndIf
      
      FrontColor(100,100,100)
      Box(200, 600, 100, 100)
        
      StopDrawing()
    EndIf
    
    StopPrinting()
  EndIf
EndIf
; ExecutableFormat=Windows
; EOF
But if you run this in the new IDE with debugger on, it gives an error at the loadfont() line. What is the problem? This used to work before the latest update. :(

Re: LoadFont not allowed between Drawing Start/Stop

Posted: Wed Oct 19, 2005 9:03 pm
by va!n
it make no logical sence to load a font inside start/stopdrawing! so you have to change your coding style! for example when drawing a text every loop by using start/stop drawing... do you really want to load the font every frame when calling your start/stop drawing part i dont think so! so please load the font before using it! (outsite of your mainloop / start/stop drawing loop!

Btw, its not a bug by purebasic!

Posted: Wed Oct 19, 2005 9:09 pm
by benny
no matter if it makes sense or not ... as PB&J Lover says ... the source is from
the official help (printer-example) - so it's not his personal coding style :!:

Posted: Wed Oct 19, 2005 9:10 pm
by PB&J Lover
Read my first line again. This code is the example from the PureBasic help file. It is not my code. :shock:

This worked before the new update. Where does the line belong then? If I put it where you suggest I get another error :?
no current 2d drawing object

Posted: Wed Oct 19, 2005 10:08 pm
by va!n
@PB&J Lover:
Sorry when my words has been a bit strange! Btw, i havent read that it was the example file... so sorry!

this works fine...

Code: Select all

If PrintRequester()
 
 hImage = LoadImage(0, "Data\PureBasic.bmp")
 hFont1 = LoadFont(0, "Arial",  30)
 hFont2 = LoadFont(1, "Arial", 100)

 If StartPrinting("PureBasic Test")
   If StartDrawing(PrinterOutput())
    DrawingFont(UseFont(0))
    Locate(100, 100) : DrawText("PureBasic Printer Test Font1")
    DrawingFont(UseFont(1))
    Locate(100, 400) : DrawText("PureBasic Printer Test Font2")
    DrawImage(UseImage(0), 200, 600)
    Box(200, 600, 100, 100,RGB(100,100,100))
    StopDrawing()
   EndIf
   StopPrinting()
 EndIf

EndIf
[Edited]
i am still a bit wondering... because the original printer.pb example file has no info header like all the other examples..

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Module example file
;
;    (c) 200x - Fantaisie Software
;
; ------------------------------------------------------------
;

Posted: Sun Oct 23, 2005 8:21 pm
by Andre
I will update the docs later. :wink:

Posted: Wed Nov 16, 2005 12:36 pm
by jacfrosty
Is it me or has no one actually answered the question here, why has this funcationallity changed?

This is causing me a lot of problems as I have written a some generic barcode label printing routines that can be passed the fontname and fontsize for each different field on a label. This gets loaded in for each of these at the time of print. This software has been working very nicely for a year or so now and my company relies on it very much.

Now I am told my coding style is bad and I should come up with a work around. This is not so easy. Now I need to alter my program, it will no longer run. So can I ask the question again, is this a bug or is a change of functionallity?? If so why??

Kind regards

David.

Posted: Wed Nov 16, 2005 12:43 pm
by Fred
There was a problem when loading a font inside a startdrawing() block because in some case the previous font could be still in use in the graphic context and thus won't be properly released (ie: memory leak). This a not bad programming style or anything, just a change to enforce than you won't have an unexpected crash very difficult to spot due to this (as an user got). I think you can still do a StopDrawing()/StartDrawing() again around the LoadFont() it should fix it.

Posted: Wed Nov 16, 2005 1:10 pm
by jacfrosty
Thanks for the quick reply Fred, but forgive me as I am still a little confused. Are you saying you can put things back to way is was or is it going stay like this and I will have to work around it?

Kind regards

David.

Posted: Wed Nov 16, 2005 1:46 pm
by Fred
Now we won't change this, as it could lead to unexpected crashs.

Posted: Wed Nov 16, 2005 1:59 pm
by jacfrosty
OK, I understand.

I am a little disappointed as I have a lot of generic routines that now become un-generic routines. I will have to hard code these routines into every program every time I need to change the font or size of font. Oh Hum.. Such is Life.

Again thanks for clearing the matter up.

Kind regards

David.

Posted: Wed Nov 16, 2005 2:56 pm
by Fred
If your program was working well (and you don't want to spend some time to change it), you can just put 'DisableDebugger/EnableDebugger' around the LoadFont() call, it will disable the runtime check. Then it should work like before (with a possibility of unexpected crash as explained above).

Posted: Wed Nov 16, 2005 3:23 pm
by jacfrosty
Thanks Fred, I didn't think of that.

That has worked a treat, I have now been able to make my mods and everyone is happy. Thanks again.

Kind regards


David.

Posted: Wed Nov 16, 2005 3:44 pm
by DarkDragon
Well, and a GrabImage? It doesn't work:

Code: Select all

Procedure ViewImage()
  Win = OpenWindow(#PB_Any, 0, 0, ImageWidth(), ImageHeight(), #PB_Window_SystemMenu, "Image")
  CreateGadgetList(WindowID())
  Gadget = ImageGadget(#PB_Any, 0, 0, ImageWidth(), ImageHeight(), ImageID())
  Repeat
    Event = WindowEvent()
    If EventWindowID() = Win And Event = #PB_Event_CloseWindow
      Quit = 1
    Else
      UseWindow(Win)
      ActivateWindow()
    EndIf
    Delay(10)
  Until Quit = 1
  CloseWindow(Win)
EndProcedure

b1 = CreateImage(0, 512, 512)
StartDrawing(ImageOutput())
For k=0 To 256 Step 16
  Box(k, k, 512-k, 512-k, RGB(Random(255), Random(255), Random(255)))
Next
StopDrawing()

b2 = CreateImage(1, 512, 512)
StartDrawing(ImageOutput())
For k=0 To 256 Step 16
  Ellipse(256, 256, 256-k, 256-k, RGB(Random(255), Random(255), Random(255)))
Next
StopDrawing()

UseImage(0)
StartDrawing(ImageOutput())
GrabImage(1, 2, 0, 0, 256, 256)
DrawImage(UseImage(2), 0, 0)
FreeImage(2)
StopDrawing()

UseImage(0) : ViewImage()
UseImage(1) : ViewImage()
And I need to Grab it 48x48x3 times and draw it onto another image and free it then. Maybe 48x48x3 will get 64x64x3, but it is even slow with 48x48x3

Posted: Wed Nov 16, 2005 5:23 pm
by Fred
Why don't you put the GrabImage() outside of the startdrawing ?