Graphics Functions Return Errors

Linux specific forum
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Graphics Functions Return Errors

Post 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.
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Graphics Functions Return Errors

Post by StarBootics »

Without a code snippet, it's very difficult to help you.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
mk-soft
Always Here
Always Here
Posts: 5387
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Graphics Functions Return Errors

Post by mk-soft »

DrawText on WindowOutput don´t with gtk3, use subsystem gtk2...
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: Graphics Functions Return Errors

Post 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
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: Graphics Functions Return Errors

Post 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

User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Graphics Functions Return Errors

Post 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:
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: Graphics Functions Return Errors

Post 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
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Graphics Functions Return Errors

Post 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()...
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: Graphics Functions Return Errors

Post 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
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Graphics Functions Return Errors

Post 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:
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: Graphics Functions Return Errors

Post by chris319 »

That fixed the problem, thank you.
Post Reply