Comment 6 for bug 1572154

Revision history for this message
Kyle Nitzsche (knitzsche) wrote :

The cause of the bug is registering a category the first time it is needed, saving its ptr to a var, and then reusing it as needed.

But, sometimes, the category pointer no longer exists, for example when a user taps Cancel after a search.

The solution has two parts:

1) monitor whether the query is still valid and return as quickly as possibly if the query is not valid. This is the case when the user taps Cancel: the query is not valid any more. This is general good housekeeping that notices when the user has tapped Cancel. Per comment #4, in this use case the shell issues two queries in rapid succession. The agg scope needs to notice the first is cancelled and start fresh with the second.

2) don't use a var to hold a pointer to a category. Instead, every time a category is needed: check with the unity scope shell to see if the category is registered and if it is not, the register it. Then get the pointer to the category from the shell, and use it directly.

In general, the code for point 2) looks like this:
                         if (!upstream_reply->lookup_category(cat_id))
                            {
                               upstream_reply->register_category
                               (
                                    cat_id,
                                    cat_title,
                                    "",
                                    us::CategoryRenderer(rdr)
                               );
                             }
                             res.set_category(upstream_reply->lookup_category(cat_id));