Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: could not access 'index' before initialization #337

Merged
merged 2 commits into from
Jan 3, 2023

Conversation

mmcardle
Copy link
Contributor

Hi,

Working on using cornerstone3d in a Vite project, ran into an issue when running the project.
I think I have narrowed it down to a possibly circular dependency in packages/tools/src/tools/CrosshairsTool.ts when importing liangBarksyClip
Happy to provide an example minimal repository with the error to verify.

Console error

cornerstonejs.bd843ac7.js:18089 Uncaught ReferenceError: Cannot access 'index' before initialization
    at cornerstonejs.bd843ac7.js:18089:29

with index being

...
const { RENDERING_DEFAULTS } = CONSTANTS;
const { liangBarksyClip } = index;
function defaultReferenceLineColor() {
  return "rgb(0, 200, 0)";
}
...

@netlify
Copy link

netlify bot commented Dec 17, 2022

Deploy Preview for cornerstone-3d-docs ready!

Name Link
🔨 Latest commit fa8db42
🔍 Latest deploy log https://app.netlify.com/sites/cornerstone-3d-docs/deploys/63a7795aa2b4380008436f44
😎 Deploy Preview https://deploy-preview-337--cornerstone-3d-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@santomon
Copy link

santomon commented Dec 18, 2022

wow this is incredible! I had the same issue and only just now found the same fix independently;

If only I found your PR a little earlier...

I wonder what's causing this behaviour? the import itself seems logical to me;

On a different note, how did you find this out?

I am just happy to be able to finally work with cornerstone3D in my astro build

@mmcardle
Copy link
Contributor Author

I have created an example app with the failure here https://github.com/mmcardle/cornerstone-vite

@mmcardle
Copy link
Contributor Author

wow this is incredible! I had the same issue and only just now found the same fix independently;

If only I found your PR a little earlier...

I wonder what's causing this behaviour? the import itself seems logical to me;

On a different note, how did you find this out?

I am just happy to be able to finally work with cornerstone3D in my astro build

I suspect the issue is with Vite and not with cornerstone3d.

To figure out the problem and fix i used the Contributing Guide on Linking to build my own version of cornerstonejs/tools with the fix in this PR.

When i used this my custom build of cornerstone/tools in my Vite project I stopped getting the error.

@sedghi
Copy link
Member

sedghi commented Dec 21, 2022

So is this PR fixing your issue with vite?

@mmcardle
Copy link
Contributor Author

So is this PR fixing your issue with vite?

Yes it does, although I would still like to find the underlying Vite issue as this fix feels like a superficial workaround to delay the import of liangBarksyClip.

@sedghi
Copy link
Member

sedghi commented Dec 21, 2022

can you try direct import in that file? import liangBarksyClip from '....../utilities/math/vec2/liangBarksyClip

@mmcardle
Copy link
Contributor Author

can you try direct import in that file? import liangBarksyClip from '....../utilities/math/vec2/liangBarksyClip

Yes that also works, probably a better fix to do the import like that?

@sedghi sedghi changed the title Cannot access 'index' before initialization (Vite build) fix: could not access 'index' before initialization Jan 3, 2023
@sedghi sedghi merged commit f4b7ff8 into cornerstonejs:main Jan 3, 2023
sedghi pushed a commit that referenced this pull request Jan 6, 2023
* fix: mouse-up should not unhighlight annotations (#305)

* fix: annotation highlighted and tooling for ellipticalROI

* update build

* fix tests

* chore(release): publish [skip ci]

 - docs@0.7.8
 - @cornerstonejs/tools@0.29.7

* fix: stack viewport flip scroll (#304)

* fix: use focal point for pan cache for stack viewport

* fix: pan dir with flip

* fix pan values while flipped

* update build

* apply review comments

* fix build

* chore(release): publish [skip ci]

 - @cornerstonejs/core@0.21.5
 - docs@0.7.9
 - @cornerstonejs/streaming-image-volume-loader@0.6.6
 - @cornerstonejs/tools@0.29.8

* feat: add referenceCursors tool (#275)

* added basic cursorCrosshairSync tool with example, TODO: for now cursorSync is displayed regardless of distance, create configurable distance and also sync the position of all viewports over which the mouse is not to scroll to a slice that is close to the currentMousePosition in 3d space

* addde stack syncing for StackViewport and syncing for volumeViewport on imageChange events, added configuration for max display distance

* refactored tool functions

* added comment to possible bug

* added configuration options to example

* changed look of crosshair to 4 lines with central space

* undid local tsconfig change

* undid yarn.lock changes

* added tool to example-info.json

* removed from example-runner because it broke build

* readded example and fixed typo

* readded example-info and changed example to trigger rebuild

* added cleanup for mouseoverElement when tool is disabled

* added cleanup when tool gets disabled, this does not get called when toolGroup gets destroyed, might cause remaining listeners

* applied naming changes, reworked adding annotation logic

* removed event listeners and moved logic to check for stack scrolling into rendering logic

* added planeDistanceToPoint to planar utilities

* added getClosestStackImageIndexForPoint

* rewrote logic to use onCameraModified

* updated example-info

* fixed bug with 0 being falsey

* added logic to remove cursor if wanted

* modified toolGroup so that setting a tool active only changes the cursor to default if there is no primary mouse cursor

* fixed bug not updating disable cursor

* fixed missing parentheses from merge

* readded scrollWheel scrolling and api changes

* fixed typos

* chore(release): publish [skip ci]

 - @cornerstonejs/core@0.22.0
 - docs@0.7.10
 - @cornerstonejs/streaming-image-volume-loader@0.6.7
 - @cornerstonejs/tools@0.30.0

* fix: ZoomTool fix for polyData actors with no imageData (#308)

* chore(release): publish [skip ci]

 - docs@0.7.11
 - @cornerstonejs/tools@0.30.1

* fix: If planar annotation is not visible, filter it (#318)

Co-authored-by: edward65 <edward@afxmedical.com>

* fix: filter planarFreeHandeROI based on parallel normals instead of equal normals. (#315)

Co-authored-by: Ramon Emiliani <ramon@afxmedical.com>

* fix: get correct imageData with targetId in BaseTool (#294)

* limit disabled element not need to render

* Update BaseTool.ts

fix: get correct viewport when there are multiple viewport with same stack data

Co-authored-by: chendingmiao <cdm@tomtaw.com.cn>

* chore(release): publish [skip ci]

 - docs@0.7.12
 - @cornerstonejs/tools@0.30.2

* fix: htj2k and keymodifier (#313)

* fix(htj2k):Support htj2k in the streaming volume loader

* fix(decodeImage):Fix htj2k image decode and mouse key modifiers

* Update for PR

* update ci build

* chore(release): publish [skip ci]

 - docs@0.7.13
 - @cornerstonejs/streaming-image-volume-loader@0.6.8
 - @cornerstonejs/tools@0.30.3

* fix: coronal view should not be flipped (#321)

* chore(release): publish [skip ci]

 - @cornerstonejs/core@0.22.1
 - docs@0.7.14
 - @cornerstonejs/streaming-image-volume-loader@0.6.9
 - @cornerstonejs/tools@0.30.4

* fix: bidirectional tool when short and long axis changes (#309)

* fix rotation for handles

* fix: short axis movement

* fix: bidirectional tool incorrect interaction

* chore(release): publish [skip ci]

 - @cornerstonejs/core@0.22.2
 - docs@0.7.15
 - @cornerstonejs/streaming-image-volume-loader@0.6.10
 - @cornerstonejs/tools@0.30.5

* fix(volumeViewport): Add optional scaling as the volume can be undefined (#323)

While trying to get the volume from the cache, it can be undefined so getting the scaling attribute would throw an error in that case.
This is a quick fix

* chore(release): publish [skip ci]

 - @cornerstonejs/core@0.22.3
 - docs@0.7.16
 - @cornerstonejs/streaming-image-volume-loader@0.6.11
 - @cornerstonejs/tools@0.30.6

* fix: Use queryselector instead of firstChild to get svg-layer (#268)

* chore(release): publish [skip ci]

 - docs@0.7.17
 - @cornerstonejs/tools@0.30.7

* [wip] initial dicom-loader typescript conversion

* [wip] initial typescript conversion

* [wip] update types for tests

* feat: enable having multiple instances of the same tool and add more seg tools (#327)

* feat: add floodFill and advanced brushTool

* feat: enable adding tool instances from a parent tool class

* fix threshold and brush size

* chore(release): publish [skip ci]

 - docs@0.7.18
 - @cornerstonejs/tools@0.31.0

* feat: Add new 3D volume viewport (#281)

* Extract common volume viewport functionality to base class

* Add viewport presets

* Add utility function for applying preset to volume actor

* Add new 3D volume viewport

* Add example for VolumeViewport3D

* feat: add presets dropdown to demo

* update example info json

Co-authored-by: Luccas Correa <luccascorrea@estudio89.com.br>
Co-authored-by: Alireza <ar.sedghi@gmail.com>

* chore(release): publish [skip ci]

 - @cornerstonejs/core@0.23.0
 - docs@0.7.19
 - @cornerstonejs/streaming-image-volume-loader@0.6.12
 - @cornerstonejs/tools@0.32.0

* fix: Add coplanar check in stackImageSync callback (#335)

* Add coplanar check in stackImageSync callback

* Refactoring function

* chore(release): publish [skip ci]

 - docs@0.7.20
 - @cornerstonejs/tools@0.32.1

* fix: could not access 'index' before initialization (#337)

* Avoid circular dependancy with vite build

* Nicer import

* chore(release): publish [skip ci]

 - docs@0.7.21
 - @cornerstonejs/tools@0.32.2

* [dicom-loader] update CornerstoneWadoLoaderOptions
to include optional params

* [dicom-image-loader] types update

* [dicom-image-loader] port wadoImageLoader tests
to monorepo

* [dicom-image-loader] port changes from cornerstoneWADOImageLoader commit id 9d71753
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants