I have a problem with Purebasic Mac version (image not init)

Mac OSX specific forum
dman10001
User
User
Posts: 55
Joined: Mon Feb 25, 2013 3:04 pm

I have a problem with Purebasic Mac version (image not init)

Post by dman10001 »

trying to compile a program but keep getting the same error "Image not Initialized" when I use StartDrawing(ImageOutput(#id))

where is the problem ?

Code: Select all

; English forum: http://www.purebasic.fr/english/viewtopic.php?t=15056
; Author: localmotion34 (updated for PB 4.00 by Andre)
; Date: 11. May 2005
; OS: Windows, Linux
; Demo: Yes

; LED-Gadget
; Ok, this now has the different colours as it goes up, it also has the ability To get the current state of it
; Dance To the music!

Structure gauge
  imagegad.l
  imageid.l
  width.l
  height.l
  imagehwnd.l
  precision.l
  ticks.l
  frontcol.l
  backcol.l
  cpercent.l
EndStructure

Global NewList led.gauge()


ProcedureDLL setLEDfcol(led,col)
  SelectElement(led(),led)
  led()\frontcol = col
EndProcedure

ProcedureDLL setLEDbcol(led,col)
  SelectElement(led(),led)
  led()\backcol = col
EndProcedure


ProcedureDLL LEDgadget(number,x,y,width,height,display)
  AddElement(led())
  SelectElement(led(),number)
  led()\width=width
  led()\height=height
  led()\imageid=CreateImage(#PB_Any,led()\width,led()\height)
  StartDrawing(ImageOutput(led()\imageid))  : "THIS IS WHERE THE PROBLEM IS"
  Box(0,0,led()\width,led()\height,Black)
  ledheight=led()\height-20
  boxwidth=(led()\width-10-1)/2
  secondx= 6+boxwidth
  tickcount=0
  For a=0 To led()\height-20 Step 4
    tickcount=tickcount+1
    Box(5,a,boxwidth,3,led()\backcol)
    Box(secondx,a,boxwidth,3,led()\backcol)
  Next
  led()\ticks=tickcount
  BackColor(RGB(0,0,0))
  FrontColor(RGB(0, $FF, 0))
  DrawText((led()\width/2)-10, led()\height-15, "0%")
  StopDrawing()
  led()\imagegad=ImageGadget(#PB_Any,x,y,width,height,ImageID(led()\imageid),#PB_Image_Border)
  ProcedureReturn led()\imagegad
EndProcedure

ProcedureDLL setLEDstate(led,percent)
  SelectElement(led(),led)
  led()\cpercent = percent
  tickcount=led()\ticks
  perc.f=100/led()\ticks
  percents.f=(percent/100)
  finalpercent.f=percents*tickcount
  stringpercent.s=StrF(finalpercent)
  Result.f = Round(finalpercent, 1)
  finalresult=led()\ticks-Result
  ledheight=led()\height-20
  boxwidth=(led()\width-10-1)/2
  secondx=6+boxwidth
  StartDrawing(ImageOutput(led()\imageid))
  tickcount=0
  For a=0 To led()\height-20 Step 4
    tickcount=tickcount+1
    If tickcount>=finalresult
      Box(5,a,boxwidth,3,led()\frontcol)
      Box(secondx,a,boxwidth,3,led()\frontcol)
    Else
      Box(5,a,boxwidth,3,led()\backcol)
      Box(secondx,a,boxwidth,3,led()\backcol)
    EndIf
  Next
  Box(0,led()\height-15,led()\width,15,Black)
  BackColor(RGB(0,0,0))
  FrontColor(RGB(0, $FF, 0))
  DrawText((led()\width/2)-10, led()\height-15, Str(percent)+"%")
  StopDrawing()
  SetGadgetState(led()\imagegad,ImageID(led()\imageid))
EndProcedure

ProcedureDLL getLEDstate(led)
  SelectElement(led(),led)
  ProcedureReturn led()\cpercent
EndProcedure

ProcedureDLL Beep(freq.l, time.l)
  n.f = (freq/1000)*100
  setLEDfcol(0, RGB(n.f*2.5, 250-(n.f*2.5), 0))
  setLEDstate(0, n.f)
  Beep(freq, time)
EndProcedure

ProcedureDLL StartBeep(times)
  tempo=180
  For t=1 To times
    Beep(284,tempo)
    Beep(568,tempo)
    Beep(426,tempo)
    Beep(379,tempo)
    Beep(758,tempo)
    Beep(426,tempo)
    Beep(716,tempo)
    Beep(426,tempo)

    Beep(284,tempo)
    Beep(568,tempo)
    Beep(426,tempo)
    Beep(379,tempo)
    Beep(758,tempo)
    Beep(426,tempo)
    Beep(716,tempo)
    Beep(426,tempo)

    Beep(319,tempo)
    Beep(568,tempo)
    Beep(426,tempo)
    Beep(379,tempo)
    Beep(758,tempo)
    Beep(426,tempo)
    Beep(716,tempo)
    Beep(426,tempo)

    Beep(319,tempo)
    Beep(568,tempo)
    Beep(426,tempo)
    Beep(379,tempo)
    Beep(758,tempo)
    Beep(426,tempo)
    Beep(716,tempo)
    Beep(426,tempo)

    Beep(379,tempo)
    Beep(568,tempo)
    Beep(426,tempo)
  Next t
EndProcedure

#WindowWidth  = 390
#WindowHeight = 350
If OpenWindow(0, 100, 200, #WindowWidth, #WindowHeight, "test", #PB_Window_MinimizeGadget)
  If CreateGadgetList(WindowID(0))
    led=LEDgadget(0,50,50,75,200,0)
    setLEDbcol(0, RGB(45,60,45))
    StartBeep(2)
  EndIf

  Repeat

    EventID = WaitWindowEvent()

    If EventID = #PB_Event_Gadget

      Select EventGadget()
        Case led

      EndSelect

    EndIf

  Until EventID = #PB_Event_CloseWindow

EndIf

End
Last edited by dman10001 on Sat Mar 30, 2013 1:12 am, edited 2 times in total.
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: I have a problem with Purebasic Mac version (image not i

Post by Demivec »

There is a least one typo in the code:

Code: Select all

ProcedureDLL Beep(freq.l, time.l)
  Protected n.f = (freq/1000)*100
  setLEDfcol(0, RGB(n.f*2.5, 250-(n.f*2.5), 0))
  setLEDstate(0, n.f)
  Beep_(freq, time)  ; <==- this is a call to an API routine (this isn't a recursive procedure)
EndProcedure
This may or may not be related to the problem you are experiencing. If the program make it to the point of calling Beep() it will loop forever without really doing anything before the stack fills up.
dman10001
User
User
Posts: 55
Joined: Mon Feb 25, 2013 3:04 pm

Re: I have a problem with Purebasic Mac version (image not i

Post by dman10001 »

yes it has nothing to do with the problem, It said that the Image was not Initialized.

I believed I ran it before with no problem. What happened ?
dman10001
User
User
Posts: 55
Joined: Mon Feb 25, 2013 3:04 pm

Re: I have a problem with Purebasic Mac version (image not i

Post by dman10001 »

dman10001 wrote:yes it has nothing to do with the problem, It said that the Image was not Initialized.

StartDrawing(ImageOutput(led()\imageid)) : "THIS IS WHERE THE PROBLEM IS"

I believed I ran it before with no problem. What happened ?
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: I have a problem with Purebasic Mac version (image not i

Post by Demivec »

dman10001 wrote:
dman10001 wrote:yes it has nothing to do with the problem, It said that the Image was not Initialized.

StartDrawing(ImageOutput(led()\imageid)) : "THIS IS WHERE THE PROBLEM IS"

I believed I ran it before with no problem. What happened ?
If the image wasn't successfully created before trying to draw on it you will get this message, it is self-explanatory.

To find out more, add these lines before the line where the error occurs:

Code: Select all

If led()\imageid = #Null
  MessageRequester("Fatal Error", "Image can't be created (w:" + Str(led()\width) + ", h:" + Str(led()\height) + ")")
  End
EndIf
If the message requester appears it usually means there isn't enough memory ... though there may also be other reasons.
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 456
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: I have a problem with Purebasic Mac version (image not i

Post by Mindphazer »

I have the same problem.
The result of CreateImage is not null, so this means the creation has succeed.
But I still have the "The specified #image is not initialized" when compiling.
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
User avatar
michel51
Enthusiast
Enthusiast
Posts: 290
Joined: Mon Nov 21, 2005 10:21 pm
Location: Germany

Re: I have a problem with Purebasic Mac version (image not i

Post by michel51 »

Mindphazer wrote:I have the same problem.
The result of CreateImage is not null, so this means the creation has succeed.
But I still have the "The specified #image is not initialized" when compiling.
Same here like specified above.
michel51

Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: I have a problem with Purebasic Mac version (image not i

Post by Demivec »

Does the code get past drawing to the image if the procedures are changed from ProcedureDLL to Procedure?
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 456
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: I have a problem with Purebasic Mac version (image not i

Post by Mindphazer »

Demivec wrote:Does the code get past drawing to the image if the procedures are changed from ProcedureDLL to Procedure?
Nope...
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
Post Reply