Skip to content
This repository has been archived by the owner on Jul 3, 2023. It is now read-only.

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

Closed
JomerDev opened this issue May 24, 2018 · 17 comments
Closed

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

JomerDev opened this issue May 24, 2018 · 17 comments

Comments

@JomerDev
Copy link

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
Copy link
Owner

c-smile commented May 24, 2018

How do you "enumerating an tiscript object" ?

@JomerDev
Copy link
Author

JomerDev commented May 24, 2018

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
Copy link
Owner

c-smile commented May 24, 2018

Where k is declared?

@JomerDev
Copy link
Author

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
Copy link
Owner

c-smile commented May 24, 2018

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

@JomerDev
Copy link
Author

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
Copy link
Owner

c-smile commented May 24, 2018

Thanks for clarification.

Problem is on my side, fixing.

@JomerDev
Copy link
Author

JomerDev commented Jun 2, 2018

Thank you.
Are there any news about this problem?

@JomerDev
Copy link
Author

JomerDev commented Jun 6, 2018

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
Copy link
Owner

c-smile commented Jun 6, 2018

Thanks, fixing.

@JomerDev
Copy link
Author

JomerDev commented Jun 22, 2018

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
Copy link
Owner

c-smile commented Jun 22, 2018

Stack trace will be enough, thanks in advance.

@JomerDev
Copy link
Author

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

@c-smile
Copy link
Owner

c-smile commented Jun 22, 2018

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
Copy link
Author

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
Copy link
Owner

c-smile commented Jun 23, 2018

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
Copy link
Author

Thank you very much for the quick fix

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants