Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in to_json_string #614

Closed
alatdneg opened this issue Nov 7, 2019 · 18 comments
Closed

Crash in to_json_string #614

alatdneg opened this issue Nov 7, 2019 · 18 comments

Comments

@alatdneg
Copy link

alatdneg commented Nov 7, 2019

I've also had random SEGFAULT's when calling to_json_string more than once.

I'm playing with using the base opentimelineio code in a c++ app, but there's little documentation, so I'm not sure if I'm doing this correctly.

cheers!

opentimelineio::OPENTIMELINEIO_VERSION::Timeline *timeline_ = new opentimelineio::OPENTIMELINEIO_VERSION::Timeline("test");
opentimelineio::OPENTIMELINEIO_VERSION::ErrorStatus err;

aout(this) << timeline_->to_json_string(&err, 0) << std::endl;
aout(this) << timeline_->to_json_string(&err, 0) << std::endl;

#0 0x00007ffff466d1f7 in raise () from /lib64/libc.so.6
#1 0x00007ffff466e8e8 in abort () from /lib64/libc.so.6
#2 0x00007ffff4fa55c2 in __gnu_cxx::__verbose_terminate_handler () at ../../../../gcc/libstdc++-v3/libsupc++/vterminate.cc:95
#3 0x00007ffff4fa34a6 in __cxxabiv1::__terminate(void ()()) () at ../../../../gcc/libstdc++-v3/libsupc++/eh_terminate.cc:47
#4 0x00007ffff4fa34e1 in std::terminate () at ../../../../gcc/libstdc++-v3/libsupc++/eh_terminate.cc:57
#5 0x00007ffff4fa3723 in __cxxabiv1::__cxa_throw (obj=obj@entry=0xfe7000, tinfo=tinfo@entry=0x7ffff529f8a0 , dest=dest@entry=0x7ffff4fd36e0 std::system_error::~system_error())
at ../../../../gcc/libstdc++-v3/libsupc++/eh_throw.cc:95
#6 0x00007ffff4fd38e7 in std::__throw_system_error (__i=22) at /user_data/.tmp/bobscratch-5q6dzG/build/build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/char_traits.h:320
#7 0x00007ffff6d0b0a4 in opentimelineio::v1_0::SerializableObject::_managed_retain() () from /builds/opentimelineio/0.12.0/bd667702e4/lib/libopentimelineio.so
#8 0x00007ffff6d0c1f0 in opentimelineio::v1_0::SerializableObject::to_json_string[abi:cxx11](opentimelineio::v1_0::ErrorStatus
, int) const () from /builds/opentimelineio/0.12.0/bd667702e4/lib/libopentimelineio.so

@alatdneg
Copy link
Author

alatdneg commented Nov 7, 2019

I think it's something to do with the way the object lifetime is managed, it's not clear how you stop it auto deleting, which seems to happen when you call the json function.

@alatdneg
Copy link
Author

alatdneg commented Nov 7, 2019

It'd be really handy if the c++ libs could be used independently of the python bindings. But looking at the code, I suspect this isn't possible.

@alatdneg
Copy link
Author

alatdneg commented Nov 7, 2019

any timeline_ = otio::create_safely_typed_any(new otio::Timeline(name_));
This seems to work, not sure if that's the right way though..

@davidbaraff
Copy link
Contributor

davidbaraff commented Nov 7, 2019 via email

@alatdneg
Copy link
Author

alatdneg commented Nov 7, 2019

It looks like the default refcount is set to zero when you construct an object, as soon as you run a command that increments the count, it hits zero afterwards and then the object gets deleted.

@alatdneg
Copy link
Author

alatdneg commented Nov 7, 2019

Hmm still having problems with using any of this, it just randomly dies. I must be messing up the object lifetime preservation somehow.
Do you have to add a Retainer to every object, that's created, not just the root ?

@alatdneg
Copy link
Author

alatdneg commented Nov 7, 2019

Here's a trivial example.
otio::Timeline *tmln_ = new otio::Timeline("test");
otio::ErrorStatus err;
std::cout << tmln_->to_json_string(&err) << std::endl;
std::cout << tmln_->to_json_string(&err) << std::endl;
Produces
{
"OTIO_SCHEMA": "Timeline.1",
"metadata": {},
"name": "asd",
"global_start_time": null,
"tracks": {
"OTIO_SCHEMA": "Stack.1",
"metadata": {},
"name": "tracks",
"source_range": null,
"effects": [],
"markers": [],
"children": []
}
}
terminate called after throwing an instance of 'std::system_error'
what(): Invalid argument
Aborted

@davidbaraff
Copy link
Contributor

davidbaraff commented Nov 7, 2019 via email

@ssteinbach
Copy link
Collaborator

C++ docs are up on master now, sorry about that: https://opentimelineio.readthedocs.io/en/latest/cxx/cxx.html

@davidbaraff
Copy link
Contributor

davidbaraff commented Nov 8, 2019 via email

@alatdneg
Copy link
Author

alatdneg commented Nov 8, 2019

That seems to work, but deserializing seems broken. (or I'm doing it wrong).

otio::SerializableObject *obj = otio::SerializableObject::from_json_file(path, &err);
if(obj){
timeline_ = obj;
retainer_ = otio::SerializableObject::Retainerotio::Timeline(timeline_);
}
As soon as I try and use the duration function on the timeline object it crashes.
timeline_->duration(&err)

0 0x0000000065676e00 in ?? ()
#1 0x00000000005dde97 in opentimelineio::v1_0::Timeline::duration (this=0x7ffeb8003540, error_status=0x7ffec5de9640)
at /builds/opentimelineio/0.12.0/bd667702e4/include/opentimelineio/timeline.h:46

@davidbaraff
Copy link
Contributor

davidbaraff commented Nov 8, 2019 via email

@alatdneg
Copy link
Author

alatdneg commented Nov 8, 2019

That's pretty much it, I'm trying to deserialize a otio json file, but it crashes as soon as I try to use it.

There are no examples in the documentation for how to do this, I did say that I'm probably doing it wrong.

I'm creating a retainer before running the duration command, so it shouldn't be destroyed at this point.

@davidbaraff
Copy link
Contributor

davidbaraff commented Nov 8, 2019 via email

@alatdneg
Copy link
Author

alatdneg commented Nov 11, 2019

The declarations are outside, All I need to know is how I'm meant to deserialize a otio timeline, as my try above crashes, so I guess I'm not calling it correctly or using the wrong function.
Not sure if this function is what I should be using instead of the one above.

otio::Timeline *timeline_= nullptr;
otio::SerializableObject::Retainer<otio::Timeline> retainer_;

otio::any tmp;
if(deserialize_json_from_file(path, &tmp, &err)) {
    timeline_ = otio::any_cast<otio::Timeline *>(tmp);
    retainer_ = otio::SerializableObject::Retainer<otio::Timeline>(timeline_);
}
// crashes.
timeline_->duration(&err);

@davidbaraff
Copy link
Contributor

davidbaraff commented Nov 11, 2019 via email

@davidbaraff
Copy link
Contributor

davidbaraff commented Nov 11, 2019 via email

@alatdneg
Copy link
Author

Thanks for the help, I managed to get it working!
Though I must say this setup is very awkward, it'd be so much cleaner with shared_pointers, though I appreciate the problem with python object lifetimes.

It might make more sense if the python wrapped c++ objects where derived from the base classes with special reference counting or something.

cheers!

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

No branches or pull requests

3 participants