Author Topic: strange runtime error  (Read 722 times)

Graeme

  • Senior Community Member
  • Posts: 2684
  • Hero Points: 335
strange runtime error
« on: August 23, 2021, 01:48:50 am »
I get a strange error (invalid argument) I have no idea how to resolve.  I added xmodified to the struct below and I try to set it to zero in dlist-construct().  The error is on the line that sets xmodified to zero.  I also added makelast to see if it helped but it didn't.  Why don't xmodified and makelast appear in the stack trace?
Using V25.0.2.


Code: [Select]

struct dlist_node {
   int s_next;
   int s_prev;
   typeless s_data;
};

struct dlist {
   int s_head;   
   int s_tail;
   int max_nodes;
   bool overwrite_f;
   dlist_node nodes[];
   int free_head;
   int free_count;
   int xmodified;
   int makelast;
};

struct dlist_iterator {
   dlist * listptr;
   dlist_node_handle hndl;
};


// create a new list with nmax max nodes
void dlist_construct(dlist & dl, int nmax, bool overwritef)
{
   dl.nodes._makeempty();
   dl.s_head = dl.s_tail = -1;
   dl.max_nodes = nmax;
   dl.overwrite_f = overwritef;
   dl.free_head = -1;
   dl.free_count = 0;
   dl.xmodified = 0;     // <<<<<<<<<<<<<<  error here - invalid argument
}


Stack trace written to file: C:\Users\graem\AppData\Local\Temp\vsstack.
 Invalid argument
DLinkList.ex 145 dlist_construct(
   1:   ._typename()=dlist
   1:   .s-head=-1
   1:   .s-tail=-1
   1:   .max-nodes=100
   1:   .overwrite-f=0
   1:   .nodes=<empty>
   1:   .free-head=-1
   1:   .free-count=0
   2:   100
   3:   0
   p_window_id: 74
   p_object: OI_EDITOR
   p_name:
DLinkList.ex 184 dlist_reset(
   1:   ._typename()=dlist
   1:   .s-head=-1
   1:   .s-tail=-1
   1:   .max-nodes=100
   1:   .overwrite-f=0
   1:   .nodes=<empty>
   1:   .free-head=-1
   1:   .free-count=0
   p_window_id: 74
   p_object: OI_EDITOR
   p_name:
xretrace.ex 17548 xretrace:xretrace_clear_all_line_markers()   p_window_id: 74   p_object: OI_EDITOR   p_name:
xretrace.ex 17590 xretrace_disable()   p_window_id: 74   p_object: OI_EDITOR   p_name:
stdcmds.ex 9117 command_execute()   p_window_id: 74   p_object: OI_EDITOR   p_name:
stdcmds.ex 9432 split_insert_line()   p_window_id: 4   p_object: OI_TEXT_BOX   p_name:

Graeme

  • Senior Community Member
  • Posts: 2684
  • Hero Points: 335
Re: strange runtime error
« Reply #1 on: August 23, 2021, 01:56:48 am »
So if I move xmodified to the start of the struct the error moves to free_count and free_count is missing from the stack trace.

struct dlist {
   int xmodified;
   int s_head;   
   int s_tail;
   int max_nodes;
   bool overwrite_f;
   dlist_node nodes[];
   int free_head;
   int free_count;
   int makelast;
};


 Stack trace written to file: C:\Users\graem\AppData\Local\Temp\vsstack.
 Invalid argument
DLinkList.ex 130 dlist_construct(
   1:   ._typename()=dlist
   1:   .xmodified=-1
   1:   .s-head=-1
   1:   .s-tail=-1
   1:   .max-nodes=-1
   1:   .overwrite-f=<empty>
   1:   .nodes=<empty>
   1:   .free-head=-1
   2:   -1
   3:   <empty>
   p_window_id: 74
   p_object: OI_EDITOR
   p_name:
DLinkList.ex 184 dlist_reset(
   1:   ._typename()=dlist
   1:   .xmodified=-1
   1:   .s-head=-1
   1:   .s-tail=-1
   1:   .max-nodes=-1
   1:   .overwrite-f=<empty>
   1:   .nodes=<empty>
   1:   .free-head=-1
   p_window_id: 74
   p_object: OI_EDITOR
   p_name:
xretrace.ex 17548 xretrace:xretrace_clear_all_line_markers()   p_window_id: 74   p_object: OI_EDITOR   p_name:
xretrace.ex 17590 xretrace_disable()   p_window_id: 74   p_object: OI_EDITOR   p_name:
stdcmds.ex 9117 command_execute()   p_window_id: 74   p_object: OI_EDITOR   p_name:
stdcmds.ex 9432 split_insert_line()   p_window_id: 4   p_object: OI_TEXT_BOX   p_name:

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 3471
  • Hero Points: 466
Re: strange runtime error
« Reply #2 on: August 27, 2021, 02:29:37 pm »
The stack dump has a number of lines limit that may be cutting off the list, however, the default is 100, so I do not know why yours is truncated.  Here is some sample code that overrides the limit.

Code: [Select]
_command void dump_cb_categories() name_info(','VSARG2_READ_ONLY|VSARG2_EXECUTE_FROM_MENU_ONLY|VSARG2_REQUIRES_PRO_EDITION)
{
   orig := _default_option(VSOPTION_MAX_STACK_DUMP_ARGUMENT_NOFLINES);
   _default_option(VSOPTION_MAX_STACK_DUMP_ARGUMENT_NOFLINES, 5000);
   _dump_var(gh_cb_categories, "Categories: ");
   _default_option(VSOPTION_MAX_STACK_DUMP_ARGUMENT_NOFLINES, orig);
}

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 3471
  • Hero Points: 466
Re: strange runtime error
« Reply #3 on: August 27, 2021, 02:32:33 pm »
Also, to address the original error.  If the dlist instance is allocated in xretrace.e, and you modify DLinkList.e and reload it, the xretrace.e code is going to still be compiled with an outdated version of DLinkList.e.

Graeme

  • Senior Community Member
  • Posts: 2684
  • Hero Points: 335
Re: strange runtime error
« Reply #4 on: August 28, 2021, 11:30:22 am »
Also, to address the original error.  If the dlist instance is allocated in xretrace.e, and you modify DLinkList.e and reload it, the xretrace.e code is going to still be compiled with an outdated version of DLinkList.e.

Understood, thanks, I might have had that problem at some point.  Prior to plugins the published method for xretrace has been to run a macro that loads all of the needed modules in one go, starting with DLinkList.e.  I now have a proper _on_unload_module to shut down xretrace.  I also have a better definit and _on_load functions and xretrace is now a single module which avoids a whole heap of tricky problems, plus the xretrace lists are no longer in the state file thanks to _exit_errfile.

Code: [Select]
// kill the timer, clear markers and release resources
void _on_unload_module_xretrace(_str module_name)
{
   _str sm = strip(module_name, "B", "\'\"");
   if (_strip_filename(sm, 'PD') == 'xretrace.ex') {
      xretrace_disable();
      dsay("xretrace on-unload - time " :+ _time('G'), "xretrace");
      // https://www.epochconverter.com/
   }
}

definit()
{
   xretrace_load_config();  // from the filesystem
   if (arg(1)=="L") {
      // If this is a reload
      xretrace_disable();  // kill the timer and release resources if any
      dsay("xretrace loaded - time " :+ _time('G'), "xretrace");
      // https://www.epochconverter.com/
   }
   else
   {
      // this code does not execute on every restart - if this source module is recompiled/ rebuilt
      // automatically when slickedit starts up then this code does not execute
      xretrace_timer_handle = -1;
      xretrace_debug = false;
      xretrace_marker_type_id = -1;
   }
//...
}



Graeme

  • Senior Community Member
  • Posts: 2684
  • Hero Points: 335
Re: strange runtime error
« Reply #5 on: August 28, 2021, 11:34:00 am »
The stack dump has a number of lines limit that may be cutting off the list, however, the default is 100, so I do not know why yours is truncated.  Here is some sample code that overrides the limit.

Thanks, I think the missing items were caused by the mismatch in the size of objects in the state file versus the struct definition that had two new items.