From: Olaf Wintermann Date: Sun, 23 Feb 2025 16:08:33 +0000 (+0100) Subject: fix crash when switching notebooks X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=03f66473b101c5fa0b928eb0f88e475e89284438;p=note.git fix crash when switching notebooks --- diff --git a/application/notebook.c b/application/notebook.c index 734c3ba..cd5c636 100644 --- a/application/notebook.c +++ b/application/notebook.c @@ -85,9 +85,12 @@ void notebookmodel_reload(UiObject *obj, NotebookModel *model) { void notebookmodel_attach_note(NotebookModel *model, Note *note) { - if(model->current_note == note) { - return; // NOOP - } + // TODO: enable this optimization when possible + // currently, a reattaching a notebook will still have current_note + // but the UI binding will not be enabled + //if(model->current_note == note) { + // return; // NOOP + //} if(note && !note->model) { NoteModel *notemodel = notemodel_create(model->current_notes_pool->allocator); @@ -95,7 +98,7 @@ void notebookmodel_attach_note(NotebookModel *model, Note *note) { } notebookmodel_detach_current_note(model); - ui_attach_document(model->window->obj->ctx, note->model); + ui_attach_document(model->ctx, note->model); // TODO: this is only a workaround and should be removed when // sub-document groups are supported ui_set_group(model->window->obj->ctx, APP_STATE_NOTE_SELECTED); @@ -108,7 +111,7 @@ void notebookmodel_attach_note(NotebookModel *model, Note *note) { void notebookmodel_detach_current_note(NotebookModel *model) { if(model->current_note && model->current_note->model) { - ui_detach_document2(model->window->obj->ctx, model->current_note->model); + ui_detach_document2(model->ctx, model->current_note->model); model->current_note = NULL; } } diff --git a/ui/common/context.c b/ui/common/context.c index f7dfdd3..825ac9b 100644 --- a/ui/common/context.c +++ b/ui/common/context.c @@ -92,6 +92,7 @@ void uic_context_attach_document(UiContext *ctx, void *document) { ctx->document = document; UiContext *doc_ctx = ui_document_context(document); + doc_ctx->parent = ctx; // check if any parent context has an unbound variable with the same name // as any document variable @@ -111,7 +112,7 @@ void uic_context_attach_document(UiContext *ctx, void *document) { } } - var_ctx = ctx->parent; + var_ctx = var_ctx->parent; } } @@ -119,7 +120,7 @@ static void uic_context_unbind_vars(UiContext *ctx) { CxMapIterator mi = cxMapIterator(ctx->vars); cx_foreach(CxMapEntry*, entry, mi) { UiVar *var = entry->value; - if(var->from && var->from_ctx) { + if(var->from && var->from_ctx && var->from_ctx != ctx) { uic_save_var2(var); uic_copy_binding(var, var->from, FALSE); cxMapPut(var->from_ctx->vars_unbound, *entry->key, var->from); @@ -148,6 +149,7 @@ void uic_context_detach_document2(UiContext *ctx, void *document) { UiContext *docctx = ui_document_context(document); uic_context_unbind_vars(docctx); // unbind all doc/subdoc vars from the parent + docctx->parent = NULL; } void uic_context_detach_all(UiContext *ctx) {