Login Page - Create Account

Support Board


Date/Time: Sat, 23 Nov 2024 02:29:55 +0000



[Programming Help] - CPU Exception when Study is triggered.

View Count: 258

[2024-09-09 17:29:05]
skalaydzhiyski - Posts: 58
Hi guys,

I am trying to write a study that takes in a date range of the form "2024-09-09 13:00:00/2024-09-09 13:30:00|2024-09-09 14:00:00/2024-09-09 14:30:00" -> parses it into multiple a vector of SCDateRange -> triggers a market replay for each date range.

My study is in main.cpp and my parsing function is in helpers.cpp. It is being triggered by the ON state of a control bar button. When I load the study everything is fine, but when I press the button and it triggers the study I get this error ->
"""
2024-09-09 18:20:50.846 | #5 MES-202409-CME-USD[M] 5 Min | Chart data loading complete.
2024-09-09 18:20:50.910 | Windows error code 0: The operation completed successfully.
2024-09-09 18:20:50.910 | Windows error code 122: The data area passed to a system call is too small. | Number times message added: 36
2024-09-09 18:20:50.919 | Windows error code 0: The operation completed successfully.
2024-09-09 18:20:50.919 | Windows error code 122: The data area passed to a system call is too small. | Number times message added: 36
2024-09-09 18:20:54.839 | Warning: The Custom DLL study "phitech-backtest.scsf_TriggerBacktest" has just caused a CPU exception. *
2024-09-09 18:20:54.839 | Warning: This Custom DLL study may cause Sierra Chart to be unstable until you remove the study from the chart and restart Sierra Chart. *

"""

Can somebody please help me with this, I have been struggling for the whole day today :(
Pretty sure this is coming from my eventual misunderstanding of how persistentpointers work.

All the best,
Spas
Date Time Of Last Edit: 2024-09-09 17:30:42
attachmenthelpers.cpp - Attached On 2024-09-09 17:28:39 UTC - Size: 574 B - 74 views
attachmentmain.cpp - Attached On 2024-09-09 17:28:52 UTC - Size: 2.96 KB - 75 views
[2024-09-09 18:01:08]
User431178 - Posts: 540
Your is_init block is the source of the problem.

You are giving sc.SetPersistentPointer the address of your vector, but the vector object is destroyed when it goes out of scope at the end of the is_init block.
The result of this is a dangling pointer / pointer to nothing being stored, and then subsequently an exception when you try to work with that pointer.

Take a look at the info linked below, there is an example of an init / clean up pattern for classes, this would apply to std::vector.
ACSIL Programming Concepts: Allocating Memory for Classes
[2024-09-09 18:07:56]
skalaydzhiyski - Posts: 58
I thought I could fix the issue by following the correct new and delete patterns, but for some reason I am getting the Windows errors 0 and 122 still (even though I don't get the warning by sierra).

2024-09-10 13:17:58.852 | Chart: #5 MNQ-202409-CME-USD[M] 1 Min | Study: Trigger Backtest | backtest started
2024-09-10 13:17:58.852 | Chart: #5 MNQ-202409-CME-USD[M] 1 Min | Study: Trigger Backtest | init ranges
2024-09-10 13:17:58.852 | Chart: #5 MNQ-202409-CME-USD[M] 1 Min | Study: Trigger Backtest | ranges to run for...
2024-09-10 13:17:58.852 | Chart: #5 MNQ-202409-CME-USD[M] 1 Min | Study: Trigger Backtest | 2024-09-09 13:00:00
2024-09-10 13:17:58.852 | Chart: #5 MNQ-202409-CME-USD[M] 1 Min | Study: Trigger Backtest | 2024-09-09 13:30:00
2024-09-10 13:17:58.852 | Chart: #5 MNQ-202409-CME-USD[M] 1 Min | Study: Trigger Backtest | 2024-09-09 14:00:00
2024-09-10 13:17:58.852 | Chart: #5 MNQ-202409-CME-USD[M] 1 Min | Study: Trigger Backtest | 2024-09-09 14:30:00
2024-09-10 13:17:58.852 | Chart: #5 MNQ-202409-CME-USD[M] 1 Min | Study: Trigger Backtest | init complete
2024-09-10 13:17:58.852 | Chart: #5 MNQ-202409-CME-USD[M] 1 Min | Study: Trigger Backtest | stop previous replay
2024-09-10 13:17:58.852 | Chart: #5 MNQ-202409-CME-USD[M] 1 Min | Study: Trigger Backtest | start replay for current index -> 0
2024-09-10 13:17:58.900 | Replay 60X: MNQ-202409-CME-USD[M] 1 Min | Reloading chart.
2024-09-10 13:17:58.915 | Windows error code 0: The operation completed successfully.
2024-09-10 13:17:58.915 | Windows error code 122: The data area passed to a system call is too small. | Number times message added: 36
2024-09-10 13:17:58.924 | Windows error code 0: The operation completed successfully.
2024-09-10 13:17:58.924 | Windows error code 122: The data area passed to a system call is too small. | Number times message added: 36
2024-09-10 13:18:00.454 | Replay 60X: MNQ-202409-CME-USD[M] 1 Min | Chart data loading complete.

The functionality is working as expected -> I get both backtests for both ranges to run in sequence, but I am scared the study is screwing up Sierra somehow behind the scenes in ways I don't understand, I don't want to just hide the excepitons "under the rug".

Can you please have a look at the attachments here (updated main.cpp and helpers.cpp).

I am really struggling to understand what might be happening, so any help is welcome :/

All the best,
Date Time Of Last Edit: 2024-09-10 12:52:15
attachmenthelpers.cpp - Attached On 2024-09-10 12:44:07 UTC - Size: 1.03 KB - 79 views
attachmentmain.cpp - Attached On 2024-09-10 12:44:14 UTC - Size: 3.6 KB - 77 views
[2024-09-10 17:14:58]
skalaydzhiyski - Posts: 58
Please refer to - Every ACSIL triggered Chart Replay throws Windows error.

For the root cause analysis, this post should be ignored.

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account