2009-07-16 21 views
1

私はかなり新しいプログラマーです。 0xc0000005で:アクセス違反の書き込み場所0x00630067 Z projection.exeで0x68bce2ba(msvcp90d.dll)で"msvcp90d.dll"の未処理の例外?

未処理の例外を:私は私のプログラムからこのエラーを取得していますVC++ 2008に

を使用しています。

コンピュータはこのコードページに私を連れてきます。このコードページはかなり混乱していて、私が書かなかったものです。これは、(「この行に< -computerポイント」でmaerked)問題のあるコードとして、コードのこの部分を指す:

そうです私は自分のプログラムにコードの行にそれを絞られている
public: 
_CRTIMP2_PURE static size_t __CLRCALL_OR_CDECL _Getcat(const facet ** = 0, 
    const locale * = 0) 
{ // get category value, or -1 if no corresponding C category 
    return ((size_t)(-1)); 
} 

_CRTIMP2_PURE void __CLR_OR_THIS_CALL _Incref() 
{ // safely increment the reference count 
    _BEGIN_LOCK(_LOCK_LOCALE) 
     if (_Refs < (size_t)(-1)) 
      ++_Refs;  <-computer points to this line 
    _END_LOCK() 
} 

_CRTIMP2_PURE facet *__CLR_OR_THIS_CALL _Decref() 
{ // safely decrement the reference count, return this when dead 
    _BEGIN_LOCK(_LOCK_LOCALE) 
    if (0 < _Refs && _Refs < (size_t)(-1)) 
     --_Refs; 
    return (_Refs == 0 ? this : 0); 
    _END_LOCK() 
} 

クラッシュ(「インデックス」、また、ステージ= 1から始まるコードの4行)原因:

stringstream index; 
string fileName = ""; 
index.str("");// 

index << setw(3) << setfill('0') << stage - 1; 

fileName = "positive Z topography-" + index.str() + ".txt"; 

私をバッフルの事は私が何百も実行されたことを書いた他のプログラムの外にこのコードをコピーして貼り付けていることです何時も何の問題もなく、これまでどんなことがあったのか。

編集:ここにコード全体があります。

#include <iostream> 
#include <fstream> 
#include <sstream> 
#include <string> 
#include <iomanip> 

using namespace std; 

int main() 
{ 
    int dim = 100; 
    int steps = 9; //step 0 = 1, steps = actual steps + 1 
    int spread = 5; //number of points averaged to get a slope, must be an odd number 
    int halfSpread = (spread - 1)/2; //redefine for eazier use in program (better efficency) 

    char * partMap = new char [dim * dim * dim]; // cad data 

    // positive and negitive denote the x direction the check is moving in. Positive is 0 -> x, negitive is x -> 0. 
    unsigned short int * positiveProjection = new unsigned short int [dim * dim]; //projection arrays 
    unsigned short int * negitiveProjection = new unsigned short int [dim * dim]; 

    unsigned short int * negitiveThickness = new unsigned short int [dim * dim]; 

    double * negitiveXGradient = new double [dim * dim]; 
    double * negitiveYGradient = new double [dim * dim]; 

    stringstream index; 
    string fileName; 

    ifstream txtFile; 
    txtFile.open("3D CAD Part.txt"); 
    txtFile.read(partMap, dim * dim * dim); 
    txtFile.close(); 


    for (int stage = 1; stage < steps; stage++) 
    { 

     cout << "stage " << stage << endl; 

     //z axis projections 
     //projection order is along x then along y, during each step, along z in both directions 

     int k = 0; // z axis loop variable 

     for (int j = 0; j < dim; j++) 
     { 
      for (int i = 0; i < dim; i++) 
      { 
       k = 0; 

       while ((k != dim) && partMap[dim * ((dim - 1 - k) + dim * i) + j] < stage) 
        k++; 
       positiveProjection[dim * k + j] = k; 

       k = dim; 

       while ((k != 0) && partMap[dim * ((dim - 1 - (k - 1)) + dim * i) + j] < stage) 
        k--; 
       negitiveProjection[dim * k + j] = i; 

       while ((k != 0) && partMap[dim * ((dim - 1 - (k - 1)) + dim * i) + j] >= stage) 
        k--; 
       negitiveThickness[dim * k + j] = negitiveProjection[dim * k + j] - k; 
      } 
     } 

     // negitive dz/dx gradient 
     for (int j = 0; j < dim; j++) 
     { 

      //first loop to handle the first edge gradients 
      for (int i = 0; i < halfSpread; i++) 
       negitiveXGradient[(j * dim) + i] = (double(negitiveProjection[(j * dim) + halfSpread + i]) - double(negitiveProjection[j * dim]))/(halfSpread + i); // untested 

      //second loop to handle the main middle section 
      for (int i = halfSpread; i < dim - halfSpread; i++) 
       negitiveXGradient[(j * dim) + i] = (double(negitiveProjection[(j * dim) + i + halfSpread]) - double(negitiveProjection[(j * dim) + i - halfSpread]))/ (spread - 1); // untested 

      //third loop to handle the end edge gradients 
      for (int i = dim - halfSpread; i < dim; i++) 
       negitiveXGradient[(j * dim) + i] = (double(negitiveProjection[(j * dim) + dim - 1]) - double(negitiveProjection[j * dim + i - halfSpread]))/((dim - 1) - i + halfSpread); // untested 
     } 

     // negitive dz/dy gradient 
     for (int i = 0; i < dim; i++) 
     { 
      //first loop to handle the first edge gradients 
      for (int j = 0; j < halfSpread; j++) 
       negitiveYGradient[(j * dim) + i] = (double(negitiveProjection[((j + halfSpread) * dim) + i]) - double(negitiveProjection[i]))/(halfSpread + j); // untested 

      //second loop to handle the main middle section 
      for (int j = halfSpread; j < dim - halfSpread; j++) 
       negitiveYGradient[(j * dim) + i] = (double(negitiveProjection[((j + halfSpread) * dim) + i]) - double(negitiveProjection[((j - halfSpread) * dim) + i]))/ (spread - 1); // untested 

      //third loop to handle the end edge gradients 
      for (int j = dim - halfSpread; j < dim; j++) 
       negitiveYGradient[(j * dim) + i] = (double(negitiveProjection[(dim * (dim - 1)) + i]) - double(negitiveProjection[((j - halfSpread) * dim) + i]))/((dim - 1) - j + halfSpread); // untested 
     } 

     fileName = ""; // reset string and stringstream 
     index.str("");// 

     index << setw(3) << setfill('0') << stage - 1; // set index, index is -1 of stage due to the program structure 

     fileName = "positive Z topography-" + index.str() + ".txt"; 

     ofstream outputFile1(fileName.c_str(), std::ios::binary | std::ios::out); 
     outputFile1.write(reinterpret_cast<const char*>(positiveProjection), streamsize(dim * dim * sizeof(unsigned short int))); 
     outputFile1.close(); 

     fileName = "negitive Z topography-" + index.str() + ".txt"; 

     ofstream outputFile2(fileName.c_str(), std::ios::binary | std::ios::out); 
     outputFile2.write(reinterpret_cast<const char*>(negitiveProjection), streamsize(dim * dim * sizeof(unsigned short int))); 
     outputFile2.close(); 

     fileName = "negitive Z thickness-" + index.str() + ".txt"; 

     ofstream outputFile4(fileName.c_str(), std::ios::binary | std::ios::out); 
     outputFile4.write(reinterpret_cast<const char*>(negitiveThickness), streamsize(dim * dim * sizeof(unsigned short int)));  
     outputFile4.close(); 

     fileName = "negitive Z X gradient-" + index.str() + ".txt"; 

     ofstream outputFile5(fileName.c_str(), std::ios::binary | std::ios::out); 
     outputFile5.write(reinterpret_cast<const char*>(negitiveXGradient), streamsize(dim * dim * sizeof(double))); 
     outputFile5.close(); 

     fileName = "negitive Z Y gradient-" + index.str() + ".txt"; 

     ofstream outputFile6(fileName.c_str(), std::ios::binary | std::ios::out); 
     outputFile6.write(reinterpret_cast<const char*>(negitiveYGradient), streamsize(dim * dim * sizeof(double))); 
     outputFile6.close(); 
    } 
} 

私が結果をハードドライブに出力するコードの最後のチャンクまでは問題ありません。私はVC++のブレークポイントと最後のブレークポイントを使って、エラーが先ほどのポイント(私が投稿したコードの2番目のブロック)に来る前に正常に通過するようにしました。そして、明らかにHTMLは私のC++コードを好きではありません。

ああ、また、ループを通過する手間を省...それらはうまくいくはずです...そこに何十ものループがあります。あなたは何が起こっているのか心配する必要はありません。かなり安全です。私は最後の塊にしか問題がありません。

+0

これはプログラムからコピーされたコードですか? –

+0

これは私のプログラムからほとんどコピーされていますが、私は以前にstringstream indexとstring filenameを宣言しています。 変数について心配する必要はありません。変数について知る必要があるのは、stage = 1(私はそれを述べました)だけです。 上記のコードの大部分は、私のものではありません。私は最初の手がかりがなぜそこにあるのか、何が間違っているのか、私のデバッガが悪いと言うだけではありません。 – Faken

+0

このコードはクラスの一部であり、インデックスとファイル名はメンバですか?それが私がインデックスのメンバーデータが無効であると考えることができる唯一の理由です。あなたがスタックを吹き飛ばす関数のコードを持っていなければ...ルーチン全体を投稿できますか? –

答えて

3

を問題は、最後のチャンクで発生すると表示されていますがないとは限りませんループにエラーがないことを意味します。いずれかの配列の範囲外に出た場合は、後で表示されるまで表示されないことがあります。whileループが終了したときに、潜在的kは値dimを持っている可能性があることを意味しますが、

while ((k != dim) && partMap[dim * ((dim - 1 - k) + dim * i) + j] < stage) 
    k++; 

を持っている最初の内部whileループでは

。次の行は、あなたがインデックスにしようとしているので、dim*dim + jで任意のjためpositiveProjectionに境界の外に出ると、それが唯一の次元dim*dimを持っています

positiveProjection[dim * k + j] = k; 

を行います。

+1

ニース!私はそれほど疑われましたが、ループを歩くエネルギーはありませんでした。 –

+0

ええと...私が期待したかったのではなくても、あなたは私の問題を解決したようです。どうもありがとうございました! はい、あなたの権利。実際には、別のプログラムからこのコードをコピーして貼り付けたときに変数を変更することを怠っていました(他のプログラム名、x投影、y投影で推測できます)。プログラムは今実行されます...私はちょうど出力を確認する必要があります。 – Faken

+0

優秀!サービスにはうれしいです。 – Troubadour

1

私はかなり新しいプログラマですので、 私にこれを負担してください。

コンピュータはその後、あなたはおそらく、Visual Studioのデバッガは、このラインにあなたをもたらすことを意味コード

のこの ページに私をもたらします

);私はあなたの楽しみをしないように約束します。スタックトレース機能を使用して、デバッグ - >ウィンドウ - >コールスタックメニューをクリックします。

ただし、コードに間違いはありません。この単純なアプリケーションは完璧に動作します:

int main() 
{ 

    std::stringstream index; 
    std::string fileName = ""; 
    index.str("");// 
    int stage = 1; 
    index << std::setw(3) << std::setfill('0') << stage - 1; 
    fileName = "positive Z topography-" + index.str() + ".txt"; 
    std::cout << "Done with test.\n"; 
    return 0; 
} 

だから、あなたを助けるために、我々はあなたのコードの詳細を参照する必要があります...

+0

+1初心者はコールスタックを見る利点を理解していません – MSalters