Hello,
Am 12.06.2005 20:38 schrieb Bryce Harrington:
The first thing I would suggest is to add some error messages.
OK, I think I fixed these.
Also, it appears that return values are not being checked in inkview.cpp.
I added checks for some calls, esp. the ones ending with *_new. ;-)
However there are no checks for this circumstance in inkview, and it will just merrily stick the NULL widget into a table and carry on until it crashes. ;-)
Is it OK to print some error message to stderr and return 1 (as with the other error cases)?
The next thing to look at is if the document allocations are balanced with deletions. I.e., look in sp_svgview_show_next(). This routine is run when you move forward in the slideshow. It calls sp_document_new() to allocate a document for the current length. If it succeeds, then it creates a view and stores the pointer to the doc in ss->doc. But it doesn't appear to free the previous document - does it get freed automatically?
I don't think so. There is a call to Inkscape::GC:init(), but then I don't see any calls to release unused documents.
I'm rather clueless about this, so I tried a pretty clueless approach (marked by "XXX"):
static void sp_svgview_show_next (struct SPSlideShow *ss) { SPDocument *doc; SPDocument *prev_doc; /* XXX */ int current; doc = NULL; prev_doc = ss->doc; /* XXX */ current = ss->current; while (!doc && (current < ss->length - 1)) { doc = sp_document_new (ss->slides[++current], TRUE, false); } if (doc) { sp_view_set_document (SP_VIEW_WIDGET_VIEW (ss->view), doc); sp_document_ensure_up_to_date (doc); ss->doc = doc; ss->current = current; sp_document_unref(prev_doc); /* XXX */ } }
But this didn't show any visible effect ... So the problems are (I guess):
1) how to check if documents are freed? 2) if not, how to get them freed?
Would it work better if it did?
I hope so. :)
Also, it doesn't give any warning if sp_document_new failed.
That's true. Perhaps return with an error if doc == NULL?
Note that if this routine has any problems, then sp_svgview_show_prev, sp_svgview_goto_first, and sp_svgview_goto_last probably will have the same problems.
Yep. But these are very similar anyway, so a fix could easily be applied to these functions as well.
Anyway, the above steps should be pretty straightforward to do, and even if they don't solve the problem you're encountering, they'll definitely give us all a better idea of why inkview is failing. The inkview.cpp code is only about 500 lines, so should be fairly manageable, even if you don't have much experience yet with Inkscape's internals.
Well, I think I have to dig a little deeper into how the memory for documents is managed ...
Cheers, Christoph