Page 1 of 1

another file i/o prob.

Posted: Tue Aug 03, 2004 7:39 pm
by mrboris
i've been using xir's temp fix on the file i/o to alpha my scripts, the file read/append/and write are working, but i get a crash when i run this script:

Code: Select all

function onUse( myChar, top10 )
{
  // Open file to read
  var mFile = new UOXCFile;
  mFile.Open( "top10.dat", "r" );

  var myArray = new Array();

  // Read in the junk
  for (x=0;x<=9;x++)
  {
      myArray[x] = new Object();
      myArray[x].player = mFile.ReadUntil("\n");
      myArray[x].level = mFile.ReadUntil("\n");
      myArray[x].occ = mFile.ReadUntil("\n");
  }

  // Enter this character in array
  myArray[10] = new Object();
  myArray[10].player = myChar.name; 
  myArray[10].level = myChar.GetTag("level"); 
  myArray[10].occ = myChar.GetTag("occ"); 


 


  //Use Bubblesort algorithm to sort the array
 for ( i = 10; i >= 0; i-- )
 {
   for ( j = 0; j < i; j++ )
  	{
     if (myArray[j].level < myArray[j+1].level)
      {
        var temp = myArray[j];
        myArray[j] = myArray[j+1];
       	myArray[j+1] = temp;
      }
   	}
 }



  mFile.Close();
  
  // Open up file again to write
  mFile.Open( "top10.dat", "w" );
  // Update the file
  for (x=0;x<9;x++)
  {

    mFile.Write( myArray[x].player ); mFile.Write( "\n" );
    mFile.Write( myArray[x].level ); mFile.Write( "\n" );
    mFile.Write( myArray[x].occ ); mFile.Write( "\n" );
  }
  mFile.Write( "\n" );
  mFile.Close();

  mFile.Free();
  return false;

}
here is the error location

Code: Select all

	char *str = JS_GetStringBytes( JSVAL_TO_STRING( argv[0] ) );
	fprintf( mFile->mWrap, str );
	
	return JS_TRUE;
that is in UOXJSMethods.cpp

then here is the callsack.

Code: Select all

 	js32.dll!1004a273() 	
 	js32.dll!1000559a() 	
>	UOX3.exe!UOX::CFile_Write(JSContext * cx=0x015e8038, JSObject * obj=0x01bbb4f0, unsigned int argc=1, long * argv=0x01bca280, long * rval=0x0012e3b0)  Line 3794 + 0xf	C++
 	js32.dll!1001fe51() 	
 	js32.dll!10026465() 	
 	UOX3.exe!_CrtIsValidHeapPointer(const void * pUserData=0x00000000)  Line 1807	C
 	UOX3.exe!std::_Tree<std::_Tmap_traits<unsigned short,enum UOX::ItemTypes,std::less<unsigned short>,std::allocator<std::pair<unsigned short const ,enum UOX::ItemTypes> >,0> >::_Key(std::_Tree_nod<std::_Tmap_traits<unsigned short,enum UOX::ItemTypes,std::less<unsigned short>,std::allocator<std::pair<unsigned short const ,enum UOX::ItemTypes> >,0> >::_Node * _Pnode=0x00320000)  Line 142 + 0x12	C++
[/code]

Posted: Tue Aug 03, 2004 9:18 pm
by giwo
Sounds to me like one of those strings it is attempting to print is empty (invalid).

Whatever the case may be, it certainly needs error checking at least to circumvent the crash. :P