haxe icon indicating copy to clipboard operation
haxe copied to clipboard

Invalid_argument("index out of bounds")

Open Magnesus opened this issue 2 years ago • 6 comments

I get that error only with -hl out/main.c parameter, everything works with -hl game.hl and with -js html/js/main.js (for JS). Although I haven't yet been able to get the HL version running (the JS version is working fine) due to some issues with linux hashlink release (and windows release is giving me some error too but different - the linux version is complaining about gcc version).

My build.hxml:

-cp src -cp src/locations -cp src/stories -cp src/cutscenes -cp src/lore -cp src/lote -cp src/monsters -cp src/scenes

-main Main -lib heaps actuate hldx -hl out/main.c -D resourcesPath=res

I am using latest haxe, 4.2.5, tried also 4.24, same result.

Magnesus avatar Mar 19 '22 10:03 Magnesus

Please define the environment variable OCAMLRUNPARAM=b and paste the stacktrace that it should print.

Simn avatar Mar 19 '22 10:03 Simn

I did that and the output was the same:

/home/magnes/haxelib/actuate/1,8,9/src/motion/actuators/SimpleActuator.hx:222: characters 8-29 : Warning : Std.is is deprecated. Use Std.isOfType instead. /home/magnes/haxelib/actuate/1,8,9/src/motion/Actuate.hx:147: characters 7-40 : Warning : Std.is is deprecated. Use Std.isOfType instead. /home/magnes/haxelib/actuate/1,8,9/src/motion/Actuate.hx:248: characters 7-40 : Warning : Std.is is deprecated. Use Std.isOfType instead. /home/magnes/haxelib/actuate/1,8,9/src/motion/Actuate.hx:312: characters 8-41 : Warning : Std.is is deprecated. Use Std.isOfType instead. /home/magnes/haxelib/actuate/1,8,9/src/motion/Actuate.hx:323: characters 10-37 : Warning : Std.is is deprecated. Use Std.isOfType instead. /home/magnes/haxelib/actuate/1,8,9/src/motion/Actuate.hx:329: characters 17-43 : Warning : Std.is is deprecated. Use Std.isOfType instead. /home/magnes/haxelib/actuate/1,8,9/src/motion/actuators/MethodActuator.hx:73: characters 8-29 : Warning : Std.is is deprecated. Use Std.isOfType instead. /home/magnes/haxelib/actuate/1,8,9/src/motion/actuators/MethodActuator.hx:73: characters 33-52 : Warning : Std.is is deprecated. Use Std.isOfType instead. Invalid_argument("index out of bounds")

The warnings are present in the working version too, just the last line is added when I switch from -hl game.hl to -hl out/main.c seems Actuate library is a bit outdated.

Magnesus avatar Mar 19 '22 10:03 Magnesus

Ah, sorry, exported the variable wrong (wrote OCALM instead OCAML, lol). :)

Here is the output.

Fatal error: exception Invalid_argument("index out of bounds") Raised by primitive operation at file "src/generators/hl2c.ml", line 1199, characters 11-28 Called from file "array.ml", line 80, characters 31-48 Called from file "src/generators/hl2c.ml", line 1197, characters 1-783 Called from file "src/generators/hl2c.ml", line 1422, characters 11-35 Called from file "src/generators/genhl.ml", line 4133, characters 2-39 Called from file "src/compiler/haxe.ml", line 342, characters 2-14 Called from file "src/compiler/haxe.ml", line 1073, characters 25-72 Called from file "src/compiler/haxe.ml", line 633, characters 3-11 Called from file "src/compiler/haxe.ml", line 1238, characters 1-35

Magnesus avatar Mar 19 '22 10:03 Magnesus

This might be difficult to investigate without seeing the code. The failing lookup is ftable.(f.findex). I'm not very familiar with the code, but I think this must come from cfids and cfunctions being out of sync.

Can you try compiling with -D hl_check? I wonder if it catches that.

Simn avatar Mar 19 '22 10:03 Simn

@ncannasse Most of these alloc_fun_path calls look suspicious to me. They call lookup ctx.cfids, which might DynArray.add on cfids. That then increases the next ID, which is not going to be aligned with either cfunctions or cnatives, so the final let ftable = Array.init (Array.length code.functions + Array.length code.natives) new_entry in might end up being too small.

Though in that case I'd be surprised that this is the only problem surfacing...

Simn avatar Mar 19 '22 11:03 Simn

Interesting. Using -D hl-check gave me a different error:

Error: Unresolved method Bridge:b(@699)

Bridge is a class from old legacy code that I no longer use. Simplified version:

extern class Bridge { static function b(v:String):Void; }

I used it for JS->HAXE bridge but then I moved to HEAPS.IO and no longer needed it.

Removing it solved the problem. :)

Magnesus avatar Mar 19 '22 11:03 Magnesus