diff --git a/src/eez/core/value.h b/src/eez/core/value.h index 716b6591..280b8ec1 100644 --- a/src/eez/core/value.h +++ b/src/eez/core/value.h @@ -91,6 +91,13 @@ struct ArrayValue; struct ArrayElementValue; struct BlobRef; +#if defined(EEZ_DASHBOARD_API) +namespace flow { + extern void dashboardObjectValueIncRef(int json); + extern void dashboardObjectValueDecRef(int json); +} +#endif + //////////////////////////////////////////////////////////////////////////////// struct Value { @@ -238,6 +245,12 @@ struct Value { } } }*/ + +#if defined(EEZ_DASHBOARD_API) + if (type == VALUE_TYPE_JSON || type == VALUE_TYPE_STREAM) { + flow::dashboardObjectValueDecRef(int32Value);; + } +#endif } Value& operator = (const Value &value) { @@ -266,6 +279,12 @@ struct Value { pValueValue->refValue->refCounter++; } }*/ + +#if defined(EEZ_DASHBOARD_API) + if (type == VALUE_TYPE_JSON || type == VALUE_TYPE_STREAM) { + flow::dashboardObjectValueIncRef(value.int32Value);; + } +#endif } return *this; diff --git a/src/eez/flow/dashboard_api.cpp b/src/eez/flow/dashboard_api.cpp index 096fbddf..97c19a60 100644 --- a/src/eez/flow/dashboard_api.cpp +++ b/src/eez/flow/dashboard_api.cpp @@ -90,6 +90,18 @@ Value operationJsonClone(int json) { return result; } +void dashboardObjectValueIncRef(int json) { + EM_ASM({ + dashboardObjectValueIncRef($0, $1); + }, g_wasmModuleId, json); +} + +void dashboardObjectValueDecRef(int json) { + EM_ASM({ + dashboardObjectValueDecRef($0, $1); + }, g_wasmModuleId, json); +} + void onObjectArrayValueFree(ArrayValue *arrayValue) { EM_ASM({ onObjectArrayValueFree($0, $1); @@ -157,6 +169,7 @@ EM_PORT_API(Value *) createArrayValue(int arraySize, int arrayType) { } EM_PORT_API(Value *) createStreamValue(int value) { + dashboardObjectValueIncRef(value); auto pValue = ObjectAllocator::allocate(0x53a2e660); *pValue = Value(value, VALUE_TYPE_STREAM); return pValue; @@ -175,6 +188,7 @@ EM_PORT_API(Value *) createBlobValue(const uint8_t *buffer, uint32_t bufferLen) } EM_PORT_API(Value *) createJsonValue(int value) { + dashboardObjectValueIncRef(value); auto pValue = ObjectAllocator::allocate(0x734f514c); *pValue = Value(value, VALUE_TYPE_JSON); return pValue; diff --git a/src/eez/flow/dashboard_api.h b/src/eez/flow/dashboard_api.h index 9f037adc..d87e9e72 100644 --- a/src/eez/flow/dashboard_api.h +++ b/src/eez/flow/dashboard_api.h @@ -32,6 +32,9 @@ int operationJsonSet(int json, const char *property, const Value *valuePtr); int operationJsonArrayLength(int json); Value operationJsonClone(int json); +void dashboardObjectValueIncRef(int json); +void dashboardObjectValueDecRef(int json); + void onObjectArrayValueFree(ArrayValue *arrayValue); } // flow