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

Error: Maximum call stack #2978

Open
omarty13 opened this issue Feb 7, 2024 · 0 comments
Open

Error: Maximum call stack #2978

omarty13 opened this issue Feb 7, 2024 · 0 comments

Comments

@omarty13
Copy link

omarty13 commented Feb 7, 2024

Hello. I generate C++ code using a JS script. In place of "codeChars" I insert a very large array which represents the JS code. This code is run further by the function "napi_run_script". The problem is that if there are a lot of hardcoded symbols, something more than 200,000+, the addon compiles normally, but when connected it does not work and causes an error. In nodes I get an error - Maximum call stack size.

#include <node_api.h>
#include <stdlib.h>

namespace lib_${nameLib}
{
	static napi_value Method(napi_env env, napi_callback_info info) {
		napi_value rslt_run, str_jscode;

		int arr[] = {${codeChars}};
		int lenArr = sizeof(arr)/sizeof(int);
		char* jscode = new char[lenArr];

		for (int i = 0; i < lenArr; i++) {
			jscode[i] = arr[i];
		}

		napi_status status = napi_create_string_utf8(env, jscode, NAPI_AUTO_LENGTH, &str_jscode);

		delete[] jscode;

		if (status != napi_ok) {
			const char* message = "Error: status != napi_ok";
			napi_throw_error(env, NULL, message);
			return NULL;
		}

		napi_run_script(env, str_jscode, &rslt_run);

		return rslt_run;
	}

	static napi_value Init(napi_env env, napi_value exports) {
		return Method(env, NULL);
	}

	NAPI_MODULE(NODE_GYP_MODULE_NAME, Init);
}

Please tell me how can I fix this?

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

No branches or pull requests

1 participant