Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
How to use ccbEndProgram() correctly?

labz
Registered User
Quote
2023-06-04 15:05:15

I have made a script. And I this script I call ccbEndProgram() when ESC key is pressed. But after the window is closed, there would be a Error messagebox shown as the EXE has stopped with error.

Do I foget to release any resource here? How can I use ccbEndProgram() correctly? Thanks.


// The URL for get data
var IpAddress;
var HttpRequest=false;
var RequestID;

// Callback function for HTTP request
function finishedRequest(dataReceived)
{
print(dataReceived);
var cube = ccbGetSceneNodeFromName("cubeMesh1");
ccbSetSceneNodeProperty(cube, "Rotation",dataReceived)
// Mark HTTP request complete
HttpRequest=false;
}

// Callback function for Drawing a Frame
function onFrameDrawing()
{
// Only request when the last HTTP request is completed
if (HttpRequest==false) {
RequestID=ccbDoHTTPRequest(IpAddress, finishedRequest);
HttpRequest=true;
}
}

// We can use ESC to end the application
function keyPressedDown(keyCode)
{
// ESC key is pressed
if (keyCode == 27)
{
ccbUnregisterOnFrameEvent(onFrameDrawing);
if (HttpRequest==true) {
// Cancel the last HTTP request
ccbCancelHTTPRequest(RequestID);
}

ccbEndProgram();
}
}

// register key events
ccbRegisterKeyDownEvent("keyPressedDown");

if (ccbFileExist("config.txt")) {
IpAddress=ccbReadFileContent("config.txt")
ccbRegisterOnFrameEvent(onFrameDrawing);

} else {
print("Please set IP address in Config.txt");
}



just_in_case
Moderator
Quote
2023-06-05 08:18:38

I never tried that command, when I will be on my desktop, I will try it and will provide and answer to you.


okeoke
Registered User
Quote
2023-06-05 09:58:08

I also never used it and didn't receive any errors related to not completed requests ever.
Tbh, I'm not sure how js communicates with the core engine, but to my experience it doesn't happen on every frame. So I believe, the issue might be that ccbEndProgram is actually called multiple times. Try to also unregister keyPressedDown event if it's called. I.e. the function would be:
function keyPressedDown(keyCode)
{
// ESC key is pressed
if (keyCode == 27)
{
ccbUnregisterOnFrameEvent(onFrameDrawing);
ccbUnregisterOnFrameEvent(keyPressedDown);
if (HttpRequest==true) {
// Cancel the last HTTP request
ccbCancelHTTPRequest(RequestID);
}

ccbEndProgram();
}
}



just_in_case
Moderator
Quote
2023-06-05 12:44:58

@labz, I just tried the code that you provides, and it din't throw any error to me and work just fine.

Also I don't understand why you are using the code at first place, I don't think that you need to unregisterFramEvents and Callbacks and all before closing your app, they are not going to work in the background or won't get stored in the memory. So they won't be doing anything, all you need is just close the app.

ccbEndProgram(), does close the app, also there is an action to close the application as well, you can use that too if you want. There is no need to unregisterOnFrameEvent, and callback events, they will get destroyed too as soon as your apps get closed.


labz
Registered User
Quote
2023-06-05 13:52:35

Hi,

Thanks for your reply. I have tried your code, But this issue still happen.

wrote:
I also never used it and didn't receive any errors related to not completed requests ever.
Tbh, I'm not sure how js communicates with the core engine, but to my experience it doesn't happen on every frame. So I believe, the issue might be that ccbEndProgram is actually called multiple times. Try to also unregister keyPressedDown event if it's called. I.e. the function would be:
function keyPressedDown(keyCode)
{
// ESC key is pressed
if (keyCode == 27)
{
ccbUnregisterOnFrameEvent(onFrameDrawing);
ccbUnregisterOnFrameEvent(keyPressedDown);
if (HttpRequest==true) {
// Cancel the last HTTP request
ccbCancelHTTPRequest(RequestID);
}

ccbEndProgram();
}
}



labz
Registered User
Quote
2023-06-05 13:57:00

Hi,

Yes, you can't see this issue without my device. I use ESP32 to build a simple http server. And the data shows on it. And every frame CCB could get data from it.

I have tried to remove ccbUnregisterOnFrameEvent() in my code. But that issue still happens.

Next step, I think I should written a simple http server to help you see my issue .


wrote:
@labz, I just tried the code that you provides, and it din't throw any error to me and work just fine.

Also I don't understand why you are using the code at first place, I don't think that you need to unregisterFramEvents and Callbacks and all before closing your app, they are not going to work in the background or won't get stored in the memory. So they won't be doing anything, all you need is just close the app.

ccbEndProgram(), does close the app, also there is an action to close the application as well, you can use that too if you want. There is no need to unregisterOnFrameEvent, and callback events, they will get destroyed too as soon as your apps get closed.



labz
Registered User
Quote
2023-06-06 12:36:49

I have confirmed this issue only happens on Windows 7. I write a simple http server which can create a server on local Windows. And this issue only happens with Windows 7.

I have tried on 2 Windows 7 systems. One is my i7 4790s destop. And the other is in a virtual machine(VirtualBox). Both of them have same issue.

https://www.lab-z.com/wp-content...

If CCB is only support Windows above Windows7 I think this issue can be ignored.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "I?ternational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact