1. Machine Level Exception Error

Hi all,

I keep this error, machine level exception from line ffi.e (1065) in function c_func() (signal 11)

public constant xAG_InitCore = define_c_func(core,"+AG_InitCore",{C_STRING,C_UINT},C_INT) 
 
public function AG_InitCore(object name,atom flags) 
 return c_func(xAG_InitCore,{name,flags}) 
end function 
 
public constant xAG_InitGraphics = define_c_func(gui,"+AG_InitGraphics",{C_STRING},C_INT) 
 
public function AG_InitGraphics(sequence driver) 
	return c_func(xAG_InitGraphics,{driver}) 
end function 
 
if AG_InitCore(NULL,0) = -1 then 
	puts(1,"Failed to init AGAR!\n") 
	abort(1) 
end if 
 
if AG_InitGraphics("wgl") = -1 then --error comes from AG_InitGraphics() function 
	puts(1,"Failed to init Graphics!\n") 
	abort(1) 
end if 

https://github.com/JulNadeauCA/libagar/blob/trunk/gui/gui.h -C code attempting to be wrapped

https://libagar.org/man3/AG_InitGraphics - AGAR help files explaining AG_InitGraphics() function

--From ex.er file 
A machine-level exception occurred during execution of this statement (signal 11)  
    rid = 13 
    args = {46100240} 
    fn = 140712873640182 
    cif = 44216672 
    name = {65'A',71'G',95'_',73'I',110'n',105'i',116't',71'G',114'r',97'a', 
112'p',104'h',105'i',99'c',115's'} 
    nargs = 1 
    parg_types = 43064912 
    rtype = 1793360160 
    pargs = 43065360 
    pfree = {43065360,46099120,46099920} 
    arg_types = <no value> 
    i = 1 
    parg = <no value> 
    rtype_size = 8 
    prvalue = 46099920 
    rvalue = <no value> 
    i = 4 

new topic     » topic index » view message » categorize

2. Re: Machine Level Exception Error

I get the same error without libffi. Here is ex.err after running this macro in NotepadPlusPlus to help read sequences:

Macro clean_err 
 
replace 
[0-9]+'(.)'[,\r\n]* 
by 
\1 

C:\Users\HP\Downloads\agar_1.7.0\demo\..\include\ag_gui.e:38 in function AG_InitGraphics()  
A machine-level exception occurred during execution of this statement (signal 11)  
    win = 0 
 
... called from C:\Users\HP\Downloads\agar_1.7.0\demo\hello.ex:5  
 
 
Public & Export & Global & Local Variables 
 
 C:\Euphoria\include\std\memconst.e: 
    DEP_really_works = 1 
    use_DEP = 1 
    FREE_RID = 2 
    kernel_dll = <no value> 
    memDLL_id = <no value> 
    VirtualAlloc_rid = <no value> 
    VirtualLock_rid = <no value> 
    VirtualUnlock_rid = <no value> 
    VirtualProtect_rid = <no value> 
    GetLastError_rid = <no value> 
    GetSystemInfo_rid = <no value> 
 
 C:\Euphoria\include\std\memory.e: 
    edges_only = <no value> 
    check_calls = 1 
    VirtualFree_rid = 25 
 
 C:\Euphoria\include\std\types.e: 
    Defined_Sets = { 
                     {bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ}, 
                     {aeiouAEIOU}, 
                     { 
                       {09}, 
                       {AF}, 
                       {af} 
                     }, 
                     { 9,10,13,11,160}, 
                     { 
                       { /}, 
                       {:?}, 
                       {[`}, 
                       {{~} 
                     }, 
                     { 
                       { ~} 
                     }, 
                     { 
                       { ~}, 
                       {  }, 
                       {9,9}, 
                       {10,10}, 
                       {13,13}, 
                       {8,8}, 
                       {7,7} 
                     }, 
                     { 
                       {az} 
                     }, 
                     { 
                       {AZ} 
                     }, 
                     { 
                       {09}, 
                       {az}, 
                       {AZ} 
                     }, 
                     { 
                       {09}, 
                       {az}, 
                       {AZ}, 
                       {__} 
                     }, 
                     { 
                       {az}, 
                       {AZ} 
                     }, 
                     { 
                       {0,} 
                     }, 
                     { 
                       {0,31}, 
                       {} 
                     }, 
                     { 
                       {09} 
                     }, 
                     { 
                       {!~} 
                     }, 
                     { 
                       {0,255} 
                     }, 
                     {_}, 
                     {1,0} 
                   } 
 
 C:\Euphoria\include\std\machine.e: 
    FREE_ARRAY_RID = 1 
    page_size = 65536 
    oldprotptr = 41537520 
    kernel_dll = 140716803031040 
    memDLL_id = 140716803031040 
    VirtualAlloc_rid = 23 
    VirtualProtect_rid = 24 
    GetLastError_rid = 26 
    GetSystemInfo_rid = 27 
    vaa = <no value> 
    system_info_ptr = <no value> 
 
 C:\Euphoria\include\std\os.e: 
    cur_pid = -1 
 
 C:\Users\HP\Downloads\agar_1.7.0\demo\..\include\ag_core.e: 
    ag_core = 140716299452416 
 
 C:\Users\HP\Downloads\agar_1.7.0\demo\..\include\ag_gui.e: 
    ag_gui = 140715853414400 
 
 C:\Users\HP\Downloads\agar_1.7.0\demo\hello.ex: 
    win = <no value> 

Jean-Marc

new topic     » goto parent     » topic index » view message » categorize

3. Re: Machine Level Exception Error

Icy_Viking said...
public constant xAG_InitGraphics = define_c_func(gui,"+AG_InitGraphics",{C_STRING},C_INT) 
 
public function AG_InitGraphics(sequence driver) 
	return c_func(xAG_InitGraphics,{driver}) 
end function 

Don't you have to allocate_string(driver) (and free it) and pass that memory address in Euphoria? Or does libffi/C_STRING take care of that?

jmduro's code is passing 0, perhaps "dummy" would be a better test.

new topic     » goto parent     » topic index » view message » categorize

4. Re: Machine Level Exception Error

I corrected AG_Initcore as such:

public function AG_InitCore(object progname, integer flags)  
  atom addr, ret  
    
  if sequence(progname) then  
    addr = allocate_string(progname)  
  else  
    addr = progname  
  end if  
  ret = c_func(xAG_InitCore, {addr, flags})  
  return ret  
end function  

I still get the same error when running this piece of code:

  if (AG_InitCore("dummy", 0) = -1) or  
     (AG_InitGraphics(0) = -1) then  
    printf(2, "Init failed: %s\n", {AG_GetError()}) 
    maybe_any_key() 
    abort (1)  
  end if  

The error happens when running AG_InitGraphics(0) or AG_InitGraphics(allocate_string("dummy")).

Jean-Marc

new topic     » goto parent     » topic index » view message » categorize

5. Re: Machine Level Exception Error

jmduro said...

I corrected AG_Initcore as such:

public function AG_InitCore(object progname, integer flags)  
  atom addr, ret  
    
  if sequence(progname) then  
    addr = allocate_string(progname)  
  else  
    addr = progname  
  end if  
  ret = c_func(xAG_InitCore, {addr, flags})  
  return ret  
end function  

I still get the same error when running this piece of code:

  if (AG_InitCore("dummy", 0) = -1) or  
     (AG_InitGraphics(0) = -1) then  
    printf(2, "Init failed: %s\n", {AG_GetError()}) 
    maybe_any_key() 
    abort (1)  
  end if  

The error happens when running AG_InitGraphics(0) or AG_InitGraphics(allocate_string("dummy")).

Jean-Marc

Hi,
i basicly did the same and got it to work

atom gui = open_dll("ag_gui.dll")  
atom core = open_dll("ag_core.dll")  
?core 
?gui 
public constant xAG_InitCore = define_c_func(core,"+AG_InitCore",{C_POINTER,C_UINT},C_INT)  
  
public function AG_InitCore(object name,atom flags)  
 return c_func(xAG_InitCore,{name,flags})  
end function  
  
public constant xAG_InitGraphics = define_c_func(gui,"+AG_InitGraphics",{C_POINTER},C_INT)  
  
public function AG_InitGraphics(object  driver)  
atom dummy=0,result 
 
        if sequence(driver) then 
            dummy=allocate_string(driver) 
            driver=dummy     
        end if 
 
        result = c_func(xAG_InitGraphics,{driver})  
 
        if dummy then 
            free(dummy) 
        end if 
        return result 
end function  
  
if AG_InitCore(NULL,0) = -1 then  
        puts(1,"Failed to init AGAR!\n")  
        abort(1)  
end if  
  
if AG_InitGraphics("WGL") = -1 then  
        puts(1,"Failed to init Graphics!\n")  
        abort(1)  
end if  

But i had some dll missing on my system before i got this far.
it took me a while

13.12.2024  14:56           562.176 libfreetype-6.dll 
13.12.2024  16:15           151.731 libgcc_s_seh-1.dll 
13.12.2024  16:00           920.576 libjpeg-8.dll 
13.12.2024  16:02           247.390 libpng16-16.dll 
13.12.2024  16:05           338.088 libwinpthread-1.dll 
13.12.2024  16:12           103.256 zlib1.dll 
Passing Null seems the way to go according to the documentation
If the drivers argument is NULL (the usual case), Agar selects the "best" driver available on the current platform. 

Maybe this helps (btw i used Phix for this)
Andreas

new topic     » goto parent     » topic index » view message » categorize

6. Re: Machine Level Exception Error

#define AG_VERBOSE        0x01 /* Allow errors and warnings on the console */ 
Anything useful show up if you pass that into the flags arg of AG_InitCore()?

new topic     » goto parent     » topic index » view message » categorize

7. Re: Machine Level Exception Error

petelomax said...

#define AG_VERBOSE        0x01 /* Allow errors and warnings on the console */ 
Anything useful show up if you pass that into the flags arg of AG_InitCore()?

Hallo,
No, no reaction. But I have to improve my statement above. The whole thing dies quietly in AG_InitGraphics. No matter which parameter I pass.
i have spent the whole afternoon with this thing, my only success is that the dll's are loaded at all.

Andreas

new topic     » goto parent     » topic index » view message » categorize

8. Re: Machine Level Exception Error

petelomax said...
Icy_Viking said...
public constant xAG_InitGraphics = define_c_func(gui,"+AG_InitGraphics",{C_STRING},C_INT) 
 
public function AG_InitGraphics(sequence driver) 
	return c_func(xAG_InitGraphics,{driver}) 
end function 

Don't you have to allocate_string(driver) (and free it) and pass that memory address in Euphoria? Or does libffi/C_STRING take care of that?

jmduro's code is passing 0, perhaps "dummy" would be a better test.

C_STRING does take care of string_allocation for you. https://github.com/ghaberek/libffi-euphoria/blob/main/include/std/ffi.e

However based on the other replies, it may be better to use C_POINTER in this case. However it seems the issue still isn't resolved yet.

new topic     » goto parent     » topic index » view message » categorize

9. Re: Machine Level Exception Error

andreasWagner said...

Hi,
i basicly did the same and got it to work

But i had some dll missing on my system before i got this far.
it took me a while

13.12.2024  14:56           562.176 libfreetype-6.dll 
13.12.2024  16:15           151.731 libgcc_s_seh-1.dll 
13.12.2024  16:00           920.576 libjpeg-8.dll 
13.12.2024  16:02           247.390 libpng16-16.dll 
13.12.2024  16:05           338.088 libwinpthread-1.dll 
13.12.2024  16:12           103.256 zlib1.dll 
Passing Null seems the way to go according to the documentation
If the drivers argument is NULL (the usual case), Agar selects the "best" driver available on the current platform. 

Maybe this helps (btw i used Phix for this)
Andreas

Hello Andreas,

With EU 4.2 64-bits, I still get the same error, eirther with AG_InitGraphics("WGL") or AG_InitGraphics(0).

Jean-Marc

new topic     » goto parent     » topic index » view message » categorize

10. Re: Machine Level Exception Error

[quote jmduro]

andreasWagner said...

Hello Andreas,

With EU 4.2 64-bits, I still get the same error, eirther with AG_InitGraphics("WGL") or AG_InitGraphics(0).

Jean-Marc

Hallo,

Yes, i just didn't see it. With Phix it dies silent without a message.
I assume that the problem cannot be solved from the outside. It lies within the dll. The debbuger shows that several exceptions are triggered. And AG.FatalError is called.

EXCEPTION_DEBUG_INFO: 
           dwFirstChance: 1 
           ExceptionCode: C0000005 (EXCEPTION_ACCESS_VIOLATION) 
          ExceptionFlags: 00000000 
        ExceptionAddress: ag_gui.00007FFF4EDAF95F 
        NumberParameters: 2 
ExceptionInformation[00]: 0000000000000001 Write 
ExceptionInformation[01]: 0000000000000000 Inaccessible Address 
Erste Ausnahme[First chance exception] bei 00007FFF4EDAF95F (C0000005, EXCEPTION_ACCESS_VIOLATION)! 
00007FFF4EDAF95F | 48:8910                  | mov qword ptr ds:[rax],rdx              | rdx:"AG_Driver" 
00007FFF4EDAF962 | 48:8B85 08010000         | mov rax,qword ptr ss:[rbp+108]          | [rbp+108]:"AG_Driver" 
00007FFF4EDAF969 | 48:8B80 D8000000         | mov rax,qword ptr ds:[rax+D8]           | 
00007FFF4EDAF970 | 48:8B95 08010000         | mov rdx,qword ptr ss:[rbp+108]          | [rbp+108]:"AG_Driver" 

But I have to be honest, I don't really know what it's supposed to mean. and I'm also slowly losing interest.

Andreas

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu