LoadFont not allowed between Drawing Start/Stop

Just starting out? Need help? Post your questions and find answers here.
PB&J Lover
Enthusiast
Enthusiast
Posts: 212
Joined: Fri Apr 22, 2005 2:07 pm
Location: U.S.A.
Contact:

LoadFont not allowed between Drawing Start/Stop

Post 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. :(
-- DB

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage — to move in the opposite direction.

Albert Einstein
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Re: LoadFont not allowed between Drawing Start/Stop

Post 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!
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
benny
Enthusiast
Enthusiast
Posts: 465
Joined: Fri Apr 25, 2003 7:44 pm
Location: end of www
Contact:

Post 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 :!:
regards,
benny!
-
pe0ple ar3 str4nge!!!
PB&J Lover
Enthusiast
Enthusiast
Posts: 212
Joined: Fri Apr 22, 2005 2:07 pm
Location: U.S.A.
Contact:

Post 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
-- DB

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage — to move in the opposite direction.

Albert Einstein
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Post 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
;
; ------------------------------------------------------------
;
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2137
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Post by Andre »

I will update the docs later. :wink:
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
jacfrosty
User
User
Posts: 21
Joined: Mon May 23, 2005 3:05 pm
Location: England, UK

Post 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.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post 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.
jacfrosty
User
User
Posts: 21
Joined: Mon May 23, 2005 3:05 pm
Location: England, UK

Post 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.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Now we won't change this, as it could lead to unexpected crashs.
jacfrosty
User
User
Posts: 21
Joined: Mon May 23, 2005 3:05 pm
Location: England, UK

Post 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.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post 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).
jacfrosty
User
User
Posts: 21
Joined: Mon May 23, 2005 3:05 pm
Location: England, UK

Post 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.
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Post 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
bye,
Daniel
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Why don't you put the GrabImage() outside of the startdrawing ?
Post Reply