You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While debugging some other issue, I've encountered an exception in CanvasManagerModel.processCommand caused by this.currentCanvas being undefined.
Steps to reproduce:
Start new notebook.
Enter and run cell from ipycanvas import Canvas, hold_canvas
Enter and run cell canvas = Canvas(width=100, height=100)
Enter and run cell canvas.fill_rect(10, 10, 20, 20)
Re-load browser window
Optional: Enable pause on exception in developer tools
Re-execute the last cell
Expected behavior:
Command executed cleanly, or a reasonably understandable exception raised in Python code and surfaced in the UI.
Actual behavior:
Error thrown: Cannot read properties of undefined (reading 'fillRect')
Hypothesis:
I believe this is most likely due to a mismatch of state. The Python _CanvasManager._current_canvas refers to the last used canvas, but on page reload the JavaScript CanvasManagerModel gets re-created and there is no machinery in place (as far as I can tell) to sync the current canvas between the two.
Potential solutions:
Have the CanvasManagerModel widget constructor signal its Python counterpart to invalidate its _current_canvas_ state. That way the next draw operation would sync state again.
Use some IPyWidgets machinery to sync the current canvas state from Python to JavaScript upon widget recreation.
I don't know enough about IPyWidgets to judge which of these approaches to prefer, or how the latter would look in more detail.
The text was updated successfully, but these errors were encountered:
While debugging some other issue, I've encountered an exception in
CanvasManagerModel.processCommand
caused bythis.currentCanvas
being undefined.Steps to reproduce:
from ipycanvas import Canvas, hold_canvas
canvas = Canvas(width=100, height=100)
canvas.fill_rect(10, 10, 20, 20)
Expected behavior:
Command executed cleanly, or a reasonably understandable exception raised in Python code and surfaced in the UI.
Actual behavior:
Error thrown: Cannot read properties of
undefined
(reading 'fillRect
')Hypothesis:
I believe this is most likely due to a mismatch of state. The Python
_CanvasManager._current_canvas
refers to the last used canvas, but on page reload the JavaScriptCanvasManagerModel
gets re-created and there is no machinery in place (as far as I can tell) to sync the current canvas between the two.Potential solutions:
CanvasManagerModel
widget constructor signal its Python counterpart to invalidate its_current_canvas_
state. That way the next draw operation would sync state again.I don't know enough about IPyWidgets to judge which of these approaches to prefer, or how the latter would look in more detail.
The text was updated successfully, but these errors were encountered: