Page 1 of 1

Graphics Functions Return Errors

Posted: Wed May 18, 2016 2:31 pm
by chris319
I am able to open a window and draw lines in it.

The functions DrawImage() and DrawText() return "Invalid memory access" errors.

What am I doing wrong?

The code works fine in Windows 7.

Re: Graphics Functions Return Errors

Posted: Wed May 18, 2016 2:43 pm
by StarBootics
Without a code snippet, it's very difficult to help you.

Best regards
StarBootics

Re: Graphics Functions Return Errors

Posted: Fri May 20, 2016 3:43 pm
by mk-soft
DrawText on WindowOutput don´t with gtk3, use subsystem gtk2...

Re: Graphics Functions Return Errors

Posted: Wed May 25, 2016 11:01 am
by chris319
Compiling with gtk2 returned the following error:

Code: Select all

Window.a(OpenWindow.o): In function `SetAcceptFocusTimerCallback':
OpenWindow.c:(.text+0xa): undefined reference to `gtk_window_set_accept_focus'
Window.a(OpenWindow.o): In function `ConfigureHandler':
OpenWindow.c:(.text+0x39): undefined reference to `g_type_check_instance_cast'
OpenWindow.c:(.text+0x48): undefined reference to `g_object_get_data'
OpenWindow.c:(.text+0x5e): undefined reference to `g_type_check_instance_cast'
OpenWindow.c:(.text+0x70): undefined reference to `g_object_set_data'
...
collect2: error: ld returned 1 exit status

Re: Graphics Functions Return Errors

Posted: Wed May 25, 2016 12:01 pm
by chris319
Here is a simple test program. The window can't be drawn into. LineXY does nothing. DrawText() results in "Invalid memory access"

Code: Select all

OpenWindow(0, 0, 0, 640, 480, "PureBasic Test", #PB_Window_SystemMenu)

SetWindowColor(0,$880000)

StartDrawing(WindowOutput(0))
LineXY(0,0, 100,100,$ffffff)
;DrawText(50,50,"Here I am")
StopDrawing()

Repeat
event = WaitWindowEvent()

Select event

Case #PB_Event_CloseWindow
  CloseWindow(0)
  End

EndSelect

ForEver
Another test program that doesn't work, taken from an example in the documentation:

Code: Select all

If OpenWindow(0, 0, 0, 220, 100, "Example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
        StartDrawing(WindowOutput(0))
          Box(10, 10, 50, 50, RGB(255, 0, 0)) 
        StopDrawing()

    Repeat
      Event = WaitWindowEvent()

    Until Event = #PB_Event_CloseWindow
  EndIf


Re: Graphics Functions Return Errors

Posted: Wed May 25, 2016 2:22 pm
by Shardik
If you want to directly draw into a window you have to detect all redraw events (and depending on the OS also resize events and possibly others) in your window and redraw all the content following each redraw event. It's the same problem you may experience in Linux, MacOS and Windows!

You are right that your 2nd example (seems) to work on Windows 7. But just add the flag #PB_Window_SizeGadget to your window definition, run the modified example and resize the window to its smallest possible size. Then resize it to a bigger size and you will see that the content won't be drawn again...

I have modified your second example to work with Windows 7 and Linux with both Gtk2 and Gtk3 (tested with Linux Mint 17.3 x64 "Rosa" with Cinnamon):

Code: Select all

OpenWindow(0, 100, 100, 220, 100, "Example...")

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Repaint
      StartDrawing(WindowOutput(0))
        Box(10, 10, 50, 50, RGB(255, 0, 0))
      StopDrawing()
  EndSelect
ForEver
PS: You should always state your Linux distribution, whether 32 bit or 64 bit and your desktop manager (for example Gnome 3, KDE, Cinnamon, Xfce, LXDE, MATE, etc.) in order to being better able to help you and because some Linux problems might depend on your distribution or desktop manager... :wink:

Re: Graphics Functions Return Errors

Posted: Wed May 25, 2016 4:34 pm
by chris319
Here is your example program. It doesn't work unless you comment out DrawText().

I am having a similar problem with DrawImage().

Code: Select all

    OpenWindow(0, 100, 100, 220, 100, "Example...")

    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Break
        Case #PB_Event_Repaint
          StartDrawing(WindowOutput(0))
            Box(10, 10, 50, 50, RGB(255, 0, 0))
Drawtext(20,20,"Here I am")
          StopDrawing()
      EndSelect
    ForEver
This is on Linux Mint Rosa, 64 bits, Cinnamon

Re: Graphics Functions Return Errors

Posted: Wed May 25, 2016 9:00 pm
by Shardik
chris319 wrote:Here is your example program. It doesn't work unless you comment out DrawText().
I can confirm this problem for Gtk3 (tested on Linux Mint 17.3 x64 "Rosa" with Cinnamon and Ubuntu 14.04 x64 with KDE). You currently have to use subsystem "gtk2" for DrawText() to work. mk-soft has already pointed this out:
mk-soft wrote:DrawText on WindowOutput don´t with gtk3, use subsystem gtk2...
The same holds true for DrawImage()...

Re: Graphics Functions Return Errors

Posted: Thu May 26, 2016 12:12 am
by chris319
I don't even have gtk3 on this machine.

As I have pointed out:
Compiling with gtk2 returns the following error:

Code: Select all

In function `SetAcceptFocusTimerCallback':
    OpenWindow.c:(.text+0xa): undefined reference to `gtk_window_set_accept_focus'
    Window.a(OpenWindow.o): In function `ConfigureHandler':
    OpenWindow.c:(.text+0x39): undefined reference to `g_type_check_instance_cast'
    OpenWindow.c:(.text+0x48): undefined reference to `g_object_get_data'
    OpenWindow.c:(.text+0x5e): undefined reference to `g_type_check_instance_cast'
    OpenWindow.c:(.text+0x70): undefined reference to `g_object_set_data'

    collect2: error: ld returned 1 exit status

Re: Graphics Functions Return Errors

Posted: Thu May 26, 2016 11:01 am
by Shardik
chris319 wrote:I don't even have gtk3 on this machine.
That's simply wrong. You told us that you are testing on Linux Mint Rosa x64 with Cinnamon. Linux Mint 17.3 "Rosa" is using Gtk 3.10.8 as is documented on Distrowatch in this table under the headline "Package" in the row "gtk+ (3.20.6)" for "17.3 rosa". ("3.20.6" is the most current version of Gtk3.)

Your compiling errors result because you are using subsystem "gtk2" without having installed the necessary libgtk2 dev package. So please open a console and install the missing libgtk2.0-dev:

Code: Select all

sudo apt-get install libgtk2.0-dev
and your problem with subsystem Gtk2 is solved... :wink:

Re: Graphics Functions Return Errors

Posted: Sat Jun 04, 2016 5:46 am
by chris319
That fixed the problem, thank you.