simple-yet-powerful-srt-subtitle-parser-cpp icon indicating copy to clipboard operation
simple-yet-powerful-srt-subtitle-parser-cpp copied to clipboard

Expression: vector subscript out of range

Open TheEeveeLovers opened this issue 1 year ago • 4 comments

When I try to load captions, the parser doesn't even start because of the following error: image Call Stack:

>	SRTSynchedLyrics.exe!std::vector<std::string,std::allocator<std::string>>::operator[](const unsigned __int64 _Pos) Line 1948	C++
 	SRTSynchedLyrics.exe!SubtitleItem::timeMSec(std::string value) Line 313	C++
 	SRTSynchedLyrics.exe!SubtitleItem::SubtitleItem(int subNo, std::string startTime, std::string endTime, std::string text, bool ignore, std::string justDialogue, int speakerCount, int nonDialogueCount, int styleTagCount, int wordCount, std::vector<std::string,std::allocator<std::string>> speaker, std::vector<std::string,std::allocator<std::string>> nonDialogue, std::vector<std::string,std::allocator<std::string>> styleTags, std::vector<std::string,std::allocator<std::string>> word) Line 286	C++
 	SRTSynchedLyrics.exe!SubRipParser::parse(std::string fileName) Line 248	C++
 	SRTSynchedLyrics.exe!SubRipParser::SubRipParser(std::string fileName) Line 262	C++
 	SRTSynchedLyrics.exe!SubtitleParserFactory::getParser() Line 155	C++
 	SRTSynchedLyrics.exe!LoadCaptions(std::string filePath) Line 35	C++
 	SRTSynchedLyrics.exe!startup() Line 212	C++
 	SRTSynchedLyrics.exe!SDL_main(int argc, char * * args) Line 223	C++
 	SRTSynchedLyrics.exe!main_getcmdline() Line 82	C
 	[External Code]	

Code:

void LoadCaptions(std::string filePath) {
	SubtitleParserFactory* subParserFactory = new SubtitleParserFactory(filePath);
	SubtitleParser* parser = subParserFactory->getParser(); // Error suspect
	// More code that doesn't get run due to error
}

LoadCaptions("12 All Apologies 1.srt");

SRT File: (zipped so it can upload to GitHub) 12 All Apologies 1.zip For reference, this file works completely fine in VLC.

TheEeveeLovers avatar Feb 17 '24 01:02 TheEeveeLovers

I added a new line character at the beginning of the SRT file and got the same error, not before getting another Run-Time Check Failure #3 - The variable 'subNo' is being used without being initialized. -- srtparser.h, line 248

Call Stack:

>	SRTSynchedLyrics.exe!SubRipParser::parse(std::string fileName) Line 248	C++
 	SRTSynchedLyrics.exe!SubRipParser::SubRipParser(std::string fileName) Line 262	C++
 	SRTSynchedLyrics.exe!SubtitleParserFactory::getParser() Line 155	C++
 	SRTSynchedLyrics.exe!LoadCaptions(std::string filePath) Line 34	C++
 	SRTSynchedLyrics.exe!startup() Line 212	C++
 	SRTSynchedLyrics.exe!SDL_main(int argc, char * * args) Line 223	C++
 	SRTSynchedLyrics.exe!main_getcmdline() Line 82	C
 	[External Code]	

Seems like part of an entirely different bug? Because here, it seems that the new line character (nothing) is being read as the caption index.

TheEeveeLovers avatar Feb 17 '24 02:02 TheEeveeLovers

I just tried opening the example SRT, and it worked fine What's wrong with my file?

TheEeveeLovers avatar Feb 17 '24 02:02 TheEeveeLovers

Apparently there's too many captions Limit is 47

TheEeveeLovers avatar Feb 17 '24 02:02 TheEeveeLovers

OK, found the problem There was an additional space before the arrow on the 48th entry

TheEeveeLovers avatar Feb 17 '24 03:02 TheEeveeLovers