cornerstonejs / cornerstoneTools

A framework for tools built on top of Cornerstone.
https://tools.cornerstonejs.org/
MIT License
577 stars 453 forks source link

AddToolState - measurementData - Cannot read property 'uuid' of undefined #1206

Closed aledoyen closed 4 years ago

aledoyen commented 4 years ago

Prerequisites

Description

When upgrading from 4.12.5 to 4.13.0, this bug appeared Due to several deadlines i have -> I can't look more after the origin of this bug so i will stay on 4.12.5 for the moment (I suppose that adding a measurementData element would make the job but not sure and not the time for trying it right now) . But I think it's usefull to give you this feedback as soon as possible. TOOLS_NAME.KERISTONE_POINT is a enum of string I use for all the tools I made and use inside the application. If I can do anything to help you more, don't hesitate to ask questions. (sorry for my english by the way... 😟)

image image image

dannyrb commented 4 years ago

(sorry for my english by the way... 😟)

Please don't ever apologize for who you are. You're already going above and beyond by reporting an issue. Thank you 🤗

Here is the source for the method that is causing you trouble:

https://github.com/cornerstonejs/cornerstoneTools/blob/master/src/stateManagement/toolState.js#L27-L52

This line is the only bit that has changed recently:

measurementData.uuid = measurementData.uuid || uuidv4();

We now assign a unique ID to every measurement when it enters toolState. I guess this could blow up if you're trying to add toolState that is not an object. We should probably think about what "types" make sense to allow, and produce developer warnings if a type is used that is not supported (if any).

getnsv commented 4 years ago

Hi dannyrb,

Am getting similar error while trying to add a angle tool data to an enabled image, please can you advise what is the solution -

Test code below:

var testtoolDataString = '{"angle":{"data":[{"visible":true,"handles":{"start":{"x":92.40628941112809,"y":109.38908238107877,"highlight":true,"active":false},"end":{"x":112.40628941112809,"y":99.64666043201174,"highlight":true,"active":false,"eactive":false},"start2":{"x":92.40628941112809,"y":109.38908238107877,"highlight":true,"active":false},"end2":{"x":112.40628941112809,"y":119.38908238107877,"highlight":true,"active":false}}}]},"length":{"data":[{"visible":true,"handles":{"start":{"x":30.63388210486889,"y":77.14351868515968,"highlight":true,"active":false},"end":{"x":57.46755322260141,"y":154.21895700205096,"highlight":true,"active":false,"eactive":false}}}]}}';

cornerstoneTools.addToolState(this.state.cornerstoneElement1, 'Angle', testtoolDataString);

The error says: TypeError: Cannot create property 'uuid' on string

and it is pointing to the exact line you have mentioned: image

So I added var testallToolData = JSON.parse(testtoolDataString);

And it solved the uuid issue.

But it started another issue as given below: image

Any help hugely appreciated.

thanks in advance, Sreevani

aledoyen commented 4 years ago

Just for you, if this bug is a real problem, blocking a new release or something else of your current project: You can use the 4.12.5 version of CsTools which doesn't contain this issue. I made this temporarly because i needed to make several other features and go on another project but I dropped the idea here if it can help you during coming days.

dannyrb commented 4 years ago

@getnsv , you are setting the toolState to a string. It should be a plain javascript object that conforms to the expected shape.