iup+cd crash, how to fix?

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
oyster
Posts: 183
Joined: Oct 11, 2005 10:46

iup+cd crash, how to fix?

Postby oyster » Feb 02, 2019 4:04

thanks in advance
I am using official fbc 1.05.0-win64 and latest built iup/cd library from iup official website

the following code is adapted from Phix language's demo on https://rosettacode.org/wiki/Draw_a_pixel because the official C demo http://webserver2.tecgraf.puc-rio.br/cd/en/screenshots_src_c.html looks some long for me to grasp the main idea

however, when I run the EXE file, it crash soon. And when I compile I get( maybe all of them can be handled via cast. is cast safe?)
simple_cd.bas(12) warning 3(1): Passing different pointer types, at parameter 1
of CDCANVASACTIVATE()
simple_cd.bas(13) warning 3(1): Passing different pointer types, at parameter 1
of CDCANVASPIXEL()
simple_cd.bas(14) warning 3(1): Passing different pointer types, at parameter 1
of CDCANVASFLUSH()
simple_cd.bas(19) warning 4(1): Suspicious pointer assignment
simple_cd.bas(28) warning 3(1): Passing different pointer types, at parameter 3
of IUPSETCALLBACK()
simple_cd.bas(31) warning 3(1): Passing different pointer types, at parameter 3
of IUPSETCALLBACK()


the code

Code: Select all

#include"string.bi"
#include once"crt/stdio.bi"
#include once"IUP/iup.bi"
#include once"IUP/iupcontrols.bi"
#include once"IUP/iupcbs.bi"
#include once"cd/cd.bi"
#include once"cd/cdiup.bi"

dim shared as Ihandle ptr  cdcanvas

function redraw_cb cdecl (byval ih as Ihandle ptr , byval posx as integer, byval posy as integer) as integer
    cdCanvasActivate(cdcanvas)
    cdCanvasPixel(cdcanvas, 100, 100, CD_RED)
    cdCanvasFlush(cdcanvas)
    return IUP_DEFAULT
end function

function map_cb cdecl (byval ih as Ihandle ptr  ) as integer
    cdcanvas = cdCreateCanvas(CD_IUP, ih)
    return IUP_DEFAULT
end function

sub main()
    IupOpen(NULL, NULL)
    IupControlsOpen()
    var canvas = IupCanvas(0)
    IupSetAttribute(canvas, "RASTERSIZE", "320x240")
    IupSetCallback(canvas, "MAP_CB", @("map_cb"))
    var dlg = IupDialog(canvas)
    IupSetAttribute(dlg, "TITLE", "Draw a pixel")
    IupSetCallback(canvas, "ACTION", @("redraw_cb"))
    ' ~ IupCloseOnEscape(dlg)
    IupShow(dlg)
    IupMainLoop()
    IupClose()
end sub

main()
Slinza
Posts: 5
Joined: Jan 30, 2019 17:21

Re: iup+cd crash, how to fix?

Postby Slinza » Feb 02, 2019 7:53

Variable declared incorrectly

Code: Select all

dim shared as Ihandle ptr  cdcanvas


Try this:

Code: Select all

#include"string.bi"
#include once"crt/stdio.bi"
#include once"IUP/iup.bi"
#include once"IUP/iupcontrols.bi"
#include once"IUP/iupcbs.bi"
#include once"cd/cd.bi"
#include once"cd/cdiup.bi"

dim shared as cdCanvas ptr  cdcanvas

function redraw_cb cdecl (byval ih as Ihandle ptr) as long
    cdCanvasActivate(cdcanvas)
    cdCanvasPixel(cdcanvas, 100, 100, CD_RED)
    cdCanvasFlush(cdcanvas)
    return IUP_DEFAULT
end function

function map_cb cdecl (byval ih as Ihandle ptr) as long
    cdcanvas = cdCreateCanvas(CD_IUP, ih)
    return IUP_DEFAULT
end function

sub main()
    IupOpen(NULL, NULL)
    IupControlsOpen()
    var canvas = IupCanvas(0)
    IupSetAttribute(canvas, "RASTERSIZE", "320x240")
    IupSetCallback(canvas, "MAP_CB", @map_cb)
    var dlg = IupDialog(canvas)
    IupSetAttribute(dlg, "TITLE", "Draw a pixel")
    IupSetCallback(canvas, "ACTION", @redraw_cb)
    ' ~ IupCloseOnEscape(dlg)
    IupShow(dlg)
    IupMainLoop()
    IupClose()
end sub

main()
oyster
Posts: 183
Joined: Oct 11, 2005 10:46

Re: iup+cd crash, how to fix?

Postby oyster » Feb 02, 2019 11:21

thanks. this one does not crash
but I found that the underneath GUI interface are painted on the canvas. I have tried

Code: Select all

iupRedraw(ih, 1)
iupUpdate(ih)


in redraw_cb callback function, but nothing changed

Image
WQ1980
Posts: 41
Joined: Sep 25, 2015 12:04
Location: Russia

Re: iup+cd crash, how to fix?

Postby WQ1980 » Feb 02, 2019 18:13

oyster

can destroy canvas
can erase canvas


Code: Select all

Function redraw_cb Cdecl (ByVal ih As Ihandle Ptr) As Long

   Dim As cdCanvas Ptr cdcanvas=cdCreateCanvas(CD_IUP, ih)
   Dim As Integer ccw, cch

   ''cdCanvasActivate(cdcanvas)
   cdCanvasGetSize(cdcanvas, @ccw, @cch, NULL, NULL)
   cdCanvasForeground(cdcanvas, cdEncodeColor(255, 255,255))      
   cdCanvasBox(cdcanvas, 0, ccw, 0, cch)   
   
   
   cdCanvasForeground(cdcanvas, CD_RED)      
   ''cdCanvasPixel(cdcanvas, 100, 100, CD_RED)   
   cdCanvasBox(cdcanvas, 0, 100, 0, 100)   
   
   cdCanvasFlush(cdcanvas)
   cdKillCanvas(cdcanvas)   
   Return IUP_DEFAULT
End Function

Function map_cb Cdecl (ByVal ih As Ihandle Ptr) As Long
   Return IUP_DEFAULT
End Function

Sub main()
   IupOpen(NULL, NULL)
   ''IupControlsOpen() ''only for canvas not needed
   Var canvas = IupCanvas(0)
   IupSetAttribute(canvas, "RASTERSIZE", "320x240")
   IupSetCallback(canvas, "MAP_CB", @map_cb)
   Var dlg = IupDialog(canvas)
   IupSetAttribute(dlg, "TITLE", "Draw a pixel")
   IupSetCallback(canvas, "ACTION", @redraw_cb)
   ' ~ IupCloseOnEscape(dlg)
   IupShow(dlg)
   IupMainLoop()
   IupClose()
End Sub

main()


Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 3 guests