My dll crashes when just displaying what is in a file (it should actually 
produce a hash table from that file).

Quick explanation of situation: It's a program that creates text based on 
conditions in a game (3rd party, so this is an addon). This will then go to a 
text-to-speech system for in game voice. I'm converting to a dll based system. 
Assuming the user can choose different vehicles, based on which one the gamer 
is using a different dll would be loaded. This could be 'bike.dll', 'car.dll', 
'boat.dll', etc..

Every dll only has 2 procs for entry by the main program : initModule and 
speechModule, and based on what vehicle, different local procs to read the data 
files and generate the sentences to speak based on parameters. This 'text to 
speak' relies on files with possible sentences (so it'll be translatable into 
other languages).

**A) Main program:** Running thread to monitor game process based on output to 
3 files (updated by the game)

Loop
    gets info from thread (text & files that have altered) sends data to DLL 
(which generates a seq with lines of text to say) processes the seq returned by 
the DLL and sends those speech thread
**B) DLL**
    when the module is first loaded, one call is made to (initModule), this 
calls the proc loadSpeechData to load the file with possible text to say the 
main program loop will then repeatedly make calls to (speechModule) which uses 
dll local procs for speech generation, picking from the hash table based on 
parameters

It's in loading this text data file where it goes wrong. If the file is NOT 
loaded, the dll works fine, but cannot pick the words to say (in debug mode 
just outputs what it would pick).

That text data should go into a hash table, but even just iterating over the 
file contents makes the program crash. I've tried different memory models 
(normally --mm:ord) but with the same result. The proc loadSpeechData is in an 
imported nim source (import LoadData)
    
    
    proc loadSpeechData*(project:string = "", folder: string, language: string 
= "en") =
      debugEcho("---------------------------------------In loadSpeechData")he 
file
      var
        section, info, index: string
        speechData: string = ""
        sects: seq[string]   # will hold the key in [0] and the data in [1]
        parts: seq[string]
        
        resourceFilename: string = "VoiceData.zip"
      
      
      
      debugEcho(fmt("Loading speech data for {project:s} from 
{resourceFilename}\n"))
      
      # read in the data file from the zipped data file (TODO : depending on 
language)
      
      # Open the zip archive. This only reads the records metadata,
      # it does not read the entire archive into memory.
      try:
        let reader = openZipArchive(resourceFilename)
        
        try:
          # Extract the file contents from the archive.
          speechData = reader.extractFile("data-en.txt")
        except:
          logInfo = logInfo & fmt("- ERROR : could not load speech data\n")
          debugEcho("- ERROR: Could not load speech data")
        finally:
          reader.close()
      except:
        debugEcho(fmt("- ERROR : could not find speech data file 
{resourceFilename}"))
      
      debugEcho("DUMP speechData:")
      debugEcho(" - size:   ", (sizeof(speechData)))
      debugEcho(" - length: ", (speechData.len))
      debugEcho(" - lines:  ", (speechData.countLines))
      debugEcho(speechData)
      # clear the pronounciation and project data
      phonList.setLen(0)
      corrList.setLen(0)
      trigList.setLen(0)
      textTable.clear
      dataTable.clear
      
      for d in speechData.splitLines():
        inc countR
        let dataLine = d.uncomment
        debugEcho(fmt("READ {countR:4d}|{dataLine}"))
    
    
    Run

debugEcho(speechData) shows the whole file, but when iterating with d, 
(uncomment just strips // comments), it stops halfway the file. The traceback 
reports **prepareDealloc** and **SIGSEGV: Illegal storage access. (Attempt to 
read from nil?)** on the garbage collector, so I tried other memory models but 
with (nearly) the same result. Breaking my head over this for hours :-/. 
Strange the file shows up fine with echo, but when iterating over the lines it 
just crashes.

Here is the code (same code works fine in the pre-dll version, where it was 
statically linked. However because of the various 'vehicles' that statically 
linked version is becoming too big and won't allow plugin of new/updated 
'vehicles'.

This is the output (removed lines or it would become too long):
    
    
    DUMP speechData:
     - size:   8
     - length: 38264
     - lines:  959
    ///////////////////////////////////////////////////////////////////////
    // This file contains data for the speech system
    ... (some 950 more lines)
    TXT_ALLZEROS:all zeros
    TXT_TENSECONDS:Ten seconds
    TXT_TARGET:target
    
    READ    
1|///////////////////////////////////////////////////////////////////////
    READ    2|// This file contains data for the speech system
    ...
    READ  455|=00000;Zero
    READ  456|=_;
    READ  457|=[;
    Traceback (most recent call last)
    C:\Users\Ivan\GFR\ReModuleG.nim(216) speechModule
    C:\Users\Ivan\GFR\ReModuleG.nim(161) processPlayer
    C:\Users\Ivan\GFR\ReLangData.nim(132) loadSpeechData
    
C:\Users\Ivan\AppData\Local\Programs\nim-1.4.8_x64\nim-1.4.8\lib\pure\strformat.nim(484)
 formatValue
    
C:\Users\Ivan\AppData\Local\Programs\nim-1.4.8_x64\nim-1.4.8\lib\pure\strformat.nim(411)
 formatInt
    
C:\Users\Ivan\AppData\Local\Programs\nim-1.4.8_x64\nim-1.4.8\lib\system\gc.nim(439)
 newObj
    
C:\Users\Ivan\AppData\Local\Programs\nim-1.4.8_x64\nim-1.4.8\lib\system\gc_common.nim(423)
 prepareDealloc
    SIGSEGV: Illegal storage access. (Attempt to read from nil?)
    
    
    Run

Reply via email to