c-smile / sciter-sdk

Sciter is an embeddable HTML/CSS/scripting engine
http://sciter.com
Other
2.11k stars 224 forks source link

Enumerating a tiscript object in c++ seems to be broken #84

Closed JomerDev closed 6 years ago

JomerDev commented 6 years ago

I updated sciter-gtk.so from version 4.1.5.5856 today because of the window closure sequence bug and now enumerating an tiscript object only returns an empty key and a symbol instead of the keys and values of the object.

It works again when I replace it new .so with the old one.

c-smile commented 6 years ago

How do you "enumerating an tiscript object" ?

JomerDev commented 6 years ago

I am using the tiscript::enumerator for this.

Example:

nlohmann::json tisObjToJson( HVM vm, nlohmann::json j, tiscript::value obj ) {     tiscript::enumerator each( vm, obj );     for( tiscript::value key, val; each( key, val );) {       std::string k = aux::w2utf( tiscript::c_string( key ) ).c_str();       if( tiscript::is_string( val ) ) {         j[ k ] = strdup( aux::w2utf( tiscript::c_string( val ) ).c_str() );       } else if( tiscript::is_int( val ) ) {         j[ k ] = tiscript::c_int( val );       } else if( tiscript::is_float( val ) ) {         j[ k ] = tiscript::c_float( val );       } else if( tiscript::is_bool( val ) ) {         j[ k ] = tiscript::c_bool( val );       } else if( tiscript::is_symbol( val ) ) {         j[ k ] = strdup( aux::w2utf( tiscript::c_symbol( val ) ).c_str() );       } else if( tiscript::is_array( val ) ) {         j[ k ] = tisArrToJson( vm, nlohmann::json::array(), val );       } else if( tiscript::is_object( val ) ) {         j[ k ] = tisObjToJson( vm, nlohmann::json::object(), val );       } else {         j[ k ] = nullptr;       }     }     return j;   }

c-smile commented 6 years ago

Where k is declared?

JomerDev commented 6 years ago

Oops, I removed it accidentally while copying it to github. I added it to my previous comment. k is declared like this: std::string k = aux::w2utf( tiscript::c_string( key ) ).c_str();

c-smile commented 6 years ago

And what are "empty key and a symbol instead" exactly?

JomerDev commented 6 years ago

The only pair that gets added to the nlohmann::json object with the function above is an empty string as key "" and the value "nothing" as string. At least in the new sdk version

c-smile commented 6 years ago

Thanks for clarification.

Problem is on my side, fixing.

JomerDev commented 6 years ago

Thank you. Are there any news about this problem?

JomerDev commented 6 years ago

Thank you for the fix. But sadly there seems to be one problem remaining. It now seems like the key and value are switched, meaning that this tiscript::enumerator each( vm, obj ); for( tiscript::value key, value; each( key, value);) {}

now has the objects key in the "value" variable and the objects value in the "key" variable

c-smile commented 6 years ago

Thanks, fixing.

JomerDev commented 6 years ago

Thank you for fixing this

I'm sorry to say that I have found another Issue. Sciter crashes with a Segmentation fault when I set a mediaVar in a frame while I have at least one svg shown on screen. While I can reproduce it with libsciter-gtk.so and my code on ubuntu every time, I can't reproduce it on Windows or with usciter. I can send you a complete gdb backtrace of the functions called up to the crash,if you want to take a look at this. I didn't want to open another github issue because sadly it is really vague right now.

c-smile commented 6 years ago

Stack trace will be enough, thanks in advance.

JomerDev commented 6 years ago

The stack trace in question: https://pastebin.com/xZtBNrLj Thank you for looking into this

c-smile commented 6 years ago

Thanks, is it possible to get somehow minimal html/css/svg set where this is reproducible. So far I cannot reproduce it on smaples that I have here.

JomerDev commented 6 years ago

segfault_example.zip I've attached an example. Just start usciter, open the main.htm and click on the tab named "Crash tab". It should segfault immediately,I could reproduce it every time.

c-smile commented 6 years ago

Thanks.

One more bug of GCC code generator, or probably our mutual misunderstanding with it. Sigh.

You can take updated .so from https://github.com/c-smile/sciter-sdk/tree/master/bin.gtk/x64

JomerDev commented 6 years ago

Thank you very much for the quick fix