Skip to content

Commit

Permalink
lib: Fix ParserState::pushMedia for multiple refer to MediaSettings i…
Browse files Browse the repository at this point in the history
…n diferent order
  • Loading branch information
alanlivio committed May 9, 2018
1 parent 2ac19bc commit c8978da
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions lib/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3867,33 +3867,60 @@ ParserState::pushMedia (ParserState *st, ParserElt *elt)
// case is an refer to an Media
if (hasRefer)
{
// if referred Media not existing Media yet
media = cast (Media *, st->_doc->getObjectByIdOrAlias (refer));
// if referred Media not existing yet, create it
if (media == nullptr)
{
// only create
// when found, the Parser it will set uri, type and parent
media = new Media (refer);
g_assert (st->referMapAdd (refer, media));
// try if is an multiple refer, if not create Media
if (!st->referMapIndex (refer, &media))
{
// when Parser find the reffered Media
// (a) if an Media, the Parser will set uri, type and parent
// (b) if an MediaSettings, the Parser will replace
media = new Media (refer);
}

st->referMapAdd (refer, media);
}
// if is multiple refer to a not existing Media yet
// save refer as alias
parent = cast (Composition *, st->objStackPeek ());
g_assert_nonnull (parent);
media->addAlias (id, parent);
g_assert (st->referMapAdd (id, media));
st->referMapAdd (id, media);
}
// case is a new Media
else
{
// case is an MediaSettings
if (type == "application/x-ginga-settings")
{
refer = st->_doc->getSettings ()->getId ();
Media *tmpMedia = nullptr;

// there is only one MediaSettings
media = st->_doc->getSettings ();

// if there are refers to this MediaSettings, those refers
// are using a tmp Media, which should be this MediaSettings
st->referMapIndex (id, &tmpMedia);
if (tmpMedia)
{
auto it = st->_referMap.begin ();
while ((*it).second == tmpMedia)
{
st->_referMap[(*it).first] = media;
media->addAlias ((*it).first);
it++;
}
if (it != st->_referMap.begin ())
delete tmpMedia;
}

// add this Media as refer to MediaSettings
parent = cast (Composition *, st->objStackPeek ());
g_assert_nonnull (parent);
media->addAlias (id, parent);
g_assert (st->referMapAdd (id, media));
st->referMapAdd (id, media);
}
// case os other Media type
else
Expand Down

0 comments on commit c8978da

Please sign in to comment.