# Constraint\_error : glib-object.adb : 138 access check failed

**URL:** https://forum.ada-lang.io/t/constraint-error-glib-object-adb-138-access-check-failed/1820
**Category:** General
**Tags:** ada, gnat, linux, alire
**Created:** [February 16, 2025, 11:36am UTC](https://forum.ada-lang.io/t/constraint-error-glib-object-adb-138-access-check-failed/1820 "2025-02-16T11:36:55Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Dimitrilesdos](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/dimitrilesdos/32/607_2.png) [@Dimitrilesdos](https://forum.ada-lang.io/u/Dimitrilesdos)
#### Post date: [February 16, 2025, 11:36am UTC](https://forum.ada-lang.io/t/constraint-error-glib-object-adb-138-access-check-failed/1820/1 "2025-02-16T11:36:55Z")

</div>

please someone has an idea on how i can to solve this problem??? here is my code.

main.adb

pragma Ada\_2022;

with ada.text\_io; use ada.text\_io;  
with Gtk.Window; use Gtk.Window;  
with Gtk.Main; use Gtk.Main;  
with Gdk.Pixbuf; use Gdk.Pixbuf;  
with Glib.Error; use Glib.Error;

procedure main is

Win : Gtk\_Window;  
Pix, Pix2 : Gdk\_Pixbuf;  
Erreur : Glib.Error.GError;

begin  
Init;

Gtk\_New (Win);  
Win.Fullscreen;

Gdk\_New\_From\_File (Pix, “Image.jpg”, Erreur);  
Pix2 := Scale\_Simple (Pix, 0, 0); – line 22.

Set\_Icon (Win, Pix2);

Win.Show\_All;  
Main;  
end main;  
when i run my code, it raise an exception :

raised CONSTRAINT\_ERROR : glib-object.adb:138 access check failed  
[/home/dimitrilesdos/project/software/main/bin/main]  
0x578d21 glib\_\_object\_\_get\_object.part.0 at ???  
0x579b41 gdk\_\_pixbuf\_\_scale\_simple at ???  
0x5691ff main at main.adb:22  
0x56a682 Main at b\_\_main.adb:1093  
[/lib/x86\_64-linux-gnu/libc.so.6]  
0x7fc4ca060248  
0x7fc4ca060303  
[/home/dimitrilesdos/project/software/main/bin/main]  
0x5690bf \_start at ???  
0xfffffffffffffffe

---

<div class="post-metadata">

### Author: ![dmitry-kazakov](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/dmitry-kazakov/32/522_2.png) [@dmitry-kazakov](https://forum.ada-lang.io/u/dmitry-kazakov)
#### Post date: [February 16, 2025, 11:57am UTC](https://forum.ada-lang.io/t/constraint-error-glib-object-adb-138-access-check-failed/1820/2 "2025-02-16T11:57:14Z")

</div>

You should handle errors. Add this after Gdk\_New\_From\_File:

```ada
   Gdk_New_From_File (Pix, "Image.jpg", Erreur);
   if Erreur /= null then
      Put_Line ("Gdk_New_From_File error: " & Get_Message (Erreur));
      Error_Free (Erreur); -- Erreur must be freed
      return;
   end if;

```

---

<div class="post-metadata">

### Author: ![Dimitrilesdos](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/dimitrilesdos/32/607_2.png) [@Dimitrilesdos](https://forum.ada-lang.io/u/Dimitrilesdos)
#### Post date: [February 16, 2025, 7:26pm UTC](https://forum.ada-lang.io/t/constraint-error-glib-object-adb-138-access-check-failed/1820/3 "2025-02-16T19:26:31Z")

</div>

okay but the error message tell me that : failed to open file “image.jpg” : no such file or directory.  
However, I put the image file where my program is located. why it can’t to open the file???

---

<div class="post-metadata">

### Author: ![dmitry-kazakov](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/dmitry-kazakov/32/522_2.png) [@dmitry-kazakov](https://forum.ada-lang.io/u/dmitry-kazakov)
#### Post date: [February 16, 2025, 9:26pm UTC](https://forum.ada-lang.io/t/constraint-error-glib-object-adb-138-access-check-failed/1820/4 "2025-02-16T21:26:31Z")

</div>

Because there is no such file? “Image.jpg” /= “image.jpg” in many OSes.

BTW, when building a GTK application you can use embedded images instead of loading external files.

---

<div class="post-metadata">

### Author: ![Dimitrilesdos](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/dimitrilesdos/32/607_2.png) [@Dimitrilesdos](https://forum.ada-lang.io/u/Dimitrilesdos)
#### Post date: [February 17, 2025, 9:14am UTC](https://forum.ada-lang.io/t/constraint-error-glib-object-adb-138-access-check-failed/1820/5 "2025-02-17T09:14:57Z")

</div>

the file exists, but the program cannot find it I think. but why it not find my file??? and how to do for that it find???

---

<div class="post-metadata">

### Author: ![dmitry-kazakov](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/dmitry-kazakov/32/522_2.png) [@dmitry-kazakov](https://forum.ada-lang.io/u/dmitry-kazakov)
#### Post date: [February 17, 2025, 9:24am UTC](https://forum.ada-lang.io/t/constraint-error-glib-object-adb-138-access-check-failed/1820/6 "2025-02-17T09:24:44Z")

</div>

Use Ada.Directories.Current\_Directory to check the working directory and Ada.Directories.Exists to check the file name.

---

<div class="post-metadata">

### Author: ![Dimitrilesdos](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/dimitrilesdos/32/607_2.png) [@Dimitrilesdos](https://forum.ada-lang.io/u/Dimitrilesdos)
#### Post date: [February 17, 2025, 10:07am UTC](https://forum.ada-lang.io/t/constraint-error-glib-object-adb-138-access-check-failed/1820/7 "2025-02-17T10:07:04Z")

</div>

thanks for your help. I don’t think that it’s the only solution but it works.

> . . .  
> bool : boolean;
> 
> begin  
> . …  
> bool := Ada.Directories.exists (“image.jpg”);  
> if bool = true then  
> Gdk\_New\_From\_File (Pix,“image.jpg”, Erreur);  
> Pix2 := Scale\_Simple (Pix, 0, 0);  
> if Erreur /= null then  
> Put\_Line ("Gdk\_New\_From\_File error: " & Get\_Message (Erreur));  
> Error\_Free (Erreur); – Erreur must be freed  
> return;  
> end if;  
> end if;

---

<div class="post-metadata">

### Author: ![dmitry-kazakov](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/dmitry-kazakov/32/522_2.png) [@dmitry-kazakov](https://forum.ada-lang.io/u/dmitry-kazakov)
#### Post date: [February 17, 2025, 10:44am UTC](https://forum.ada-lang.io/t/constraint-error-glib-object-adb-138-access-check-failed/1820/8 "2025-02-17T10:44:59Z")

</div>

I use embedded images, so setting the icon never fails. I also use Set\_Icon\_List with 16x16, 24x24, 32x32 icons. GTK selects the most appropriate one for each case from the list.

When you load an external image you should not use a lossy formats like jpg and scaling. Scaling works very poorly for small images.
