iup+cd crash, how to fix?

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

iup+cd crash, how to fix?

Post by oyster »

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 ... 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?

Post by Slinza »

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: 274
Joined: Oct 11, 2005 10:46

Re: iup+cd crash, how to fix?

Post by oyster »

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: 48
Joined: Sep 25, 2015 12:04
Location: Russia

Re: iup+cd crash, how to fix?

Post by WQ1980 »

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()

Post Reply