एक सी ++ प्रोजेक्ट मैं पहली मौका अपवाद फेंकने पर समाप्त हो रहा हूं। यह डीबग मोड में विजुअल स्टूडियो 2008 में होता है जब मैं पहली बार map<pair<int,int>, int>
तक पहुंचने का प्रयास करता हूं जिसमें एक एकल कुंजी-मूल्य जोड़ी होती है। कोड के साथ तर्कसंगत रूप से कुछ भी गलत नहीं है।सी ++: अज्ञात बिंदु पर होने वाले पहले मौके के अपवाद को मैं कैसे हल कर सकता हूं?
मैंने पहले मौके के अपवादों पर पढ़ा है और समझते हैं कि वे हमेशा समस्याग्रस्त नहीं हो सकते हैं। फिर भी मैंने ऐसे सभी अपवादों को तोड़ने की कोशिश की, और जैसा कि अपेक्षित पाया गया कि कई उत्पन्न हुए हैं जो कोई मुद्दा नहीं पैदा करते हैं।
जिस कक्षा में मैं काम कर रहा हूं वह बहुत बड़ा है और इसमें कई कस्टम मेमोरी आवंटन शामिल हैं। मैं अनुमान लगाता हूं कि इनमें से कोई भी समस्या पैदा कर रहा है। हालांकि मैंने गलत होने की पहचान करने के तरीके खोजने का प्रयास करने में कई घंटे बिताए हैं, और ऐसा करने में असमर्थ रहे हैं।
पहला मौका अपवाद आउटपुट नीचे सूचीबद्ध है। यह बहुत उपयोगी नहीं है!
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x0050ae33 in theapp.exe: 0xC0000005: Access violation reading location 0x00000010.
Unhandled exception at 0x0050ae33 in theapp.exe: 0xC0000005: Access violation reading location 0x00000010.
मैं वास्तव में इस बिंदु पर संघर्ष कर रहा हूं, और यह सुनिश्चित नहीं कर रहा हूं कि कैसे आगे बढ़ना है।
क्या कोई सुझाव दे सकता है कि मैं इस समस्या से कैसे निपट सकता हूं, और पहचान सकता हूं कि क्या गलत हो रहा है? मैं आपकी सलाह के लिए बहुत आभारी हूं।
अद्यतन
यहाँ संबंधित कोड है। में सूचीबद्ध पहले अदालत बयान पर डिबगर ब्रेक के लिए नेस्ट:
// Inside operator() :
map<pair<int,int>,int> resultIdByStructIds;
pair<int,int> spair (-1,-1); // Structure pair ids reusable reference.
int nextMapEntryId = 0;
int nextNumCandidates = 0;
// For each remaining candidate.
for (int ci = 0; ci < numCandidates;) {
// If candidate has been mapped or found not viable this mapping round,
// move past it.
if (candidatesDoneThisRound[ci] == currentMappingRoundId) {
++ci;
continue;
}
Candidate candidate = candidates[ci];
const int tId = candidate.tVertexId;
const int pId = candidate.pVertexId;
// Grab the result for this structure pair.
// Create it if it doesn't exist.
// Avoid copying as slight optimisation; simply
// store pointer to true result instead.
spair.first = tInfos[tId].structure->id;
spair.second = pInfos[pId].structure->id;
// DEBUG
cout << "resultIdByStructIds size: " << resultIdByStructIds.size() << endl;
for (map<pair<int,int>,int>::const_iterator ids_id = resultIdByStructIds.begin(); ids_id != resultIdByStructIds.end(); ++ids_id) {
cout << ids_id->first.first << endl; // * Debugger breaks here.
cout << ids_id->first.second << endl;
cout << ids_id->second << endl;
printf("Structures(%i,%i) => %i\n",ids_id->first.first,ids_id->first.second,ids_id->second);
}
//
// code continues...
अद्यतन 2
यहाँ प्रश्न में नक्शे के लिए माउसओवर विवरण की एक छवि है, माइकल बुर के सुझाव के रूप में यह भ्रष्ट प्रतीत होता है।
यह पहला मौका अपवाद नहीं है जो इसे समाप्त कर रहा है, यह अनचाहे अपवाद है। –
मुझे एमएसवीएस नहीं पता है, लेकिन किसी भी तरह से "उल्लंघन का उल्लंघन" मुझे संदेह करता है कि "कोड के साथ कुछ भी गलत नहीं है" ... –
आप कहते हैं "कोड के साथ तर्कसंगत रूप से कुछ भी गलत नहीं है।"। अब तक सभी संकेत यह है कि कोड में कुछ गड़बड़ है। क्या आप हमें कोड की लाइन दिखा सकते हैं (प्रासंगिक पूर्ववर्ती रेखाओं के साथ)। –