HeapsIO / hxbit

Haxe Binary serialization and network synchronization library
155 stars 30 forks source link

Uncaught exception - std@buffer_add_char #9

Closed NuclearCookie closed 7 years ago

NuclearCookie commented 7 years ago

Hello,

I'm integrating hxbit into our fork of the openfl framework. This because the normal haxe serialization library results in huge serialization files and very slow parsing.

I've progressed quite far, but now I'm stuck. When serializing, I get this wonderful neko error message: Uncaught exception - std@buffer_add_char

I've added a callstack and it comes from this:

Called from hxbit/Serializer.hx line 141
Called from hxbit/Serializer.hx line 449
Called from hxbit/Macros.hx line 372

Which is this code:

case PMap(kt, vt):
            var kt = kt.t;
            var vt = vt.t;
            var vk = { expr : EConst(CIdent("k")), pos : v.pos };
            var vv = { expr : EConst(CIdent("v")), pos : v.pos };
            return macro $ctx.addMap($v, function(k:$kt) { trace("Test"); return hxbit.Macros.serializeValue($ctx, $vk);}, function(v:$vt) return hxbit.Macros.serializeValue($ctx, $vv));  

The only place that I can see where std@buffer_add_char could be called from, is from Query.hx:

    function readIdent() {
        var s = new StringBuf();
        while( true ) {
            var c = nextChar();
            if( (c >= 'A'.code && c <= 'Z'.code) || (c >= 'a'.code && c <= 'z'.code) || (c >= '0'.code && c <= '9'.code) || c == '_'.code || c == '-'.code )
                s.addChar(c);
            else {
                pos--;
                break;
            }
        }
        return s.toString();
    }

When calling nextChar(). However, commenting out this code still gives me the same error. I'm lost on how to progress. Do you have any clue, or can you give some tips on how to debug neko with macros? I tried to trace in several places but most places don't give me any output at all.

You can see the code here: https://github.com/FishingCactus/openfl/tree/feature/hxbit_serialization

Thanks,

Pieter

ncannasse commented 7 years ago

Hi,

I have pushed hxbit 1.2.0 on haxelib, tell me if it helps. The error might come from passing a value > 255 to addByte() since it uses a neko string buffer at the low level.

NuclearCookie commented 7 years ago

That did the trick. Thanks a lot!