#EXC_BAD_ACCESS

29 messages · Page 1 of 1 (latest)

civic flicker
#

Hello, I was programming a quick AI that predicts the next letter in a text. It worked great, but I was using vectors. Vectors are slow. I replace everything with arrays, and there you go, Thread 1: EXC_BAD_ACCESS (code=2, address=0x16f603ff8).

I am a complete beginner with c++ and may have done some stupid thing / may have missed something obvious.

I just cannot track down where the error comes from.
File is given. I use Xcode.

hexed pagodaBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

civic flicker
#

Oh btw the error message is display next to int main() { but thats surely not where it comes from

spice shell
#

vectors are slow
No, vectors aren't slow. But even slow code is better than code that causes EXC_BAD_ADDRESS

#

Run your program in the debugger and it will tell you which line causes the problem.

#

Your code does not compile

error: ‘bitset’ is not a member of ‘std’
   85 |             std::bitset<128> buffer;
      |                  ^~~~~~
#
note: ‘std::bitset’ is defined in header ‘<bitset>’; did you forget to ‘#include <bitset>’?
spice shell
#

Your arrays are too big. reduce betweenLayers to about 220

green verge
civic flicker
civic flicker
#

And xcode didnt provide me with that information

spice shell
civic flicker
#

Yeah i know, it says std::bitset is undefined and then it tells you that maybe importing <bitset> is a good idea if you use bitsets💀

#

And I did not import <bitset> in my code

civic flicker
#

fun fact: before changing to arrays, it worked with betweenLayers = 7000

#

I must have a humongus memory leak somewhere

#

WAIT

#

xcode moved its ass and finally told me what produced the error

#

std::mt19937 generator(rd());

#

rd() produces the error

#
std::random_device rd;
    std::mt19937 generator(rd());
    std::uniform_real_distribution<double> distribution(-maxVariance, maxVariance);
civic flicker
#

Ok so I fixed the random thingy

#

Now it works when I set betweenLayers to a value smaller than 479 instead of 478 yayyyy

civic flicker
#

I can put breakpoints wherever I want its not telling me anything

#

I think I'm rolling back to arrays at this point

#

*vectors