Advertisement

Class segmentation fault

Started by September 20, 2016 03:58 PM
5 comments, last by yaustar 8 years, 2 months ago
The code can be found here:
https://github.com/Nyapp/Cell/blob/master/src/classes/aggressive.h
https://github.com/Nyapp/Cell/blob/master/src/classes/bullet.h

But basically I have an array of pointers, that are all assigned a Bullet class using the new operator. However, when one of those Bullet classes tries to write to one of it's variables (like in Bullet::update()), a segfault occurs. And I tried viewing a few variables using which are supposed to be zero-initialized using cout, but I get a bunch of garbage

I can't see anywhere in Bullet.h where you assign the member variable owner. Since it also isn't initialised to null, it means that it is pointing to random data and potentially will crash when you try to deference the pointer.

I can't see anywhere in aggressiveEntity.h where you assign myBullets. Since it also isn't initialised to null, it means that it is pointing to random data and potentially will crash when you try to deference the pointer (which will happen in the update loop).

In aggressiveEntity::shoot, you 'new' an array of bullets but don't keep a reference to the array. I assume you mean to assign temp to myBullets? (Also, you have a potential memory leak here as you don't free up existing memory when create a larger array).

Steven Yau
[Blog] [Portfolio]

Advertisement
oops I forgot to upload my latest changes to the code<br>
the owner variable isn't there anymore, and I think that only now have I decided to start using an array of pointers to Bullet's scattered around in the heap instead of the Bullet's being laid out sequentially in memory
I added the following code to aggressiveEntity::shoot()
//Copy temp to myBullets
delete[] myBullets;
myBullets=temp;-
now I get this:

*** Error in `./Cell': free(): invalid pointer: 0x00007ffca4b7c990 ***======= Backtrace: =========/lib/x86_64-linux-gnu/libc.so.6(+0x77725)[0x7f75d6817725]/lib/x86_64-linux-gnu/libc.so.6(+0x7ff4a)[0x7f75d681ff4a]/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7f75d6823abc]./Cell[0x403e91]./Cell(main+0x33c)[0x4021a8]/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f75d67c0830]./Cell[0x401be9]======= Memory map: ========00400000-00406000 r-xp 00000000 08:11 3145819 /media/nyap/cfca4fc1-f4ef-4ffd-a2d3-cf6fc050941e/Programming/Projects/Cell/Cell00605000-00606000 r--p 00005000 08:11 3145819 /media/nyap/cfca4fc1-f4ef-4ffd-a2d3-cf6fc050941e/Programming/Projects/Cell/Cell00606000-00607000 rw-p 00006000 08:11 3145819 /media/nyap/cfca4fc1-f4ef-4ffd-a2d3-cf6fc050941e/Programming/Projects/Cell/Cell01084000-014f7000 rw-p 00000000 00:00 0 [heap]4025a000-402fa000 rw-p 00000000 00:00 0 4097d000-4097f000 r-xs 00000000 08:12 451232 /tmp/.glHaz8s7 (deleted)7f75a4000000-7f75a4021000 rw-p 00000000 00:00 0 7f75a4021000-7f75a8000000 ---p 00000000 00:00 0 7f75ac000000-7f75ac021000 rw-p 00000000 00:00 0 7f75ac021000-7f75b0000000 ---p 00000000 00:00 0 7f75b3ffe000-7f75b7fff000 rw-s 00000000 00:13 5 /dev/shm/pulse-shm-25375484807f75b7fff000-7f75bc000000 rw-s 00000000 00:13 12 /dev/shm/pulse-shm-28871005127f75bc000000-7f75bc021000 rw-p 00000000 00:00 0 7f75bc021000-7f75c0000000 ---p 00000000 00:00 0 7f75c0e52000-7f75c1052000 rw-s 81564000 00:06 613 /dev/nvidiactl7f75c1052000-7f75c1452000 rw-s acb96000 00:06 613 /dev/nvidiactl7f75c1452000-7f75c1852000 rw-s 1aa6d7000 00:06 613 /dev/nvidiactl7f75c1852000-7f75c1a52000 rw-s 1a9403000 00:06 613 /dev/nvidiactl7f75c1a52000-7f75c2486000 rw-p 00000000 00:00 0 7f75c2486000-7f75c2487000 ---p 00000000 00:00 0 7f75c2487000-7f75c2c87000 rw-p 00000000 00:00 0 7f75c2c87000-7f75c2c88000 ---p 00000000 00:00 0 7f75c2c88000-7f75c3488000 rw-p 00000000 00:00 0 7f75c3488000-7f75c7489000 rw-s 00000000 00:13 5 /dev/shm/pulse-shm-25375484807f75c7489000-7f75cb48a000 rw-s 00000000 00:13 11 /dev/shm/pulse-shm-28630796127f75cb48a000-7f75cb50a000 rw-s acba2000 00:06 613 /dev/nvidiactl7f75cb50a000-7f75cb58a000 rw-s 816e9000 00:06 613 /dev/nvidiactl7f75cb58a000-7f75cb60a000 rw-s b37d0000 00:06 613 /dev/nvidiactl7f75cb60a000-7f75cb70a000 rw-s 815d2000 00:06 613 /dev/nvidiactl7f75cb70a000-7f75cb71d000 rw-s 81692000 00:06 613 /dev/nvidiactl7f75cb71d000-7f75cb73d000 rw-s f0200000 00:06 614 /dev/nvidia07f75cb73d000-7f75cb77d000 rw-s 1a1bcd000 00:06 613 /dev/nvidiactl7f75cb77d000-7f75cb79d000 rw-s 17dac9000 00:06 613 /dev/nvidiactl7f75cb79d000-7f75cb7dd000 rw-s 17607e000 00:06 613 /dev/nvidiactl7f75cb7dd000-7f75ccb76000 r-xp 00000000 08:12 1205252 /usr/lib/nvidia-367/libnvidia-glcore.so.367.447f75ccb76000-7f75ccb96000 rwxp 01399000 08:12 1205252 /usr/lib/nvidia-367/libnvidia-glcore.so.367.447f75ccb96000-7f75ccf36000 r-xp 013b9000 08:12 1205252 /usr/lib/nvidia-367/libnvidia-glcore.so.367.447f75ccf36000-7f75cd136000 ---p 01759000 08:12 1205252 /usr/lib/nvidia-367/libnvidia-glcore.so.367.447f75cd136000-7f75cd4fe000 rw-p 01759000 08:12 1205252 /usr/lib/nvidia-367/libnvidia-glcore.so.367.447f75cd4fe000-7f75cd516000 rw-p 00000000 00:00 0 7f75cd516000-7f75cd519000 r-xp 00000000 08:12 1205248 /usr/lib/nvidia-367/tls/libnvidia-tls.so.367.447f75cd519000-7f75cd719000 ---p 00003000 08:12 1205248 /usr/lib/nvidia-367/tls/libnvidia-tls.so.367.447f75cd719000-7f75cd71a000 rw-p 00003000 08:12 1205248 /usr/lib/nvidia-367/tls/libnvidia-tls.so.367.447f75cd71a000-7f75cd7e2000 r-xp 00000000 08:12 1205264 /usr/lib/nvidia-367/libGLX_nvidia.so.367.447f75cd7e2000-7f75cd816000 rwxp 000c8000 08:12 1205264 /usr/lib/nvidia-367/libGLX_nvidia.so.367.447f75cd816000-7f75cd829000 r-xp 000fc000 08:12 1205264 /usr/lib/nvidia-367/libGLX_nvidia.so.367.447f75cd829000-7f75cda29000 ---p 0010f000 08:12 1205264 /usr/lib/nvidia-367/libGLX_nvidia.so.367.447f75cda29000-7f75cda51000 rw-p 0010f000 08:12 1205264 /usr/lib/nvidia-367/libGLX_nvidia.so.367.447f75cda51000-7f75cda58000 rw-p 00000000 00:00 0 7f75cda58000-7f75cdaa6000 r-xp 00000000 08:12 1205250 /usr/lib/nvidia-367/libGLdispatch.so.07f75cdaa6000-7f75cdad8000 r-xp 0004e000 08:12 1205250 /usr/lib/nvidia-367/libGLdispatch.so.07f75cdad8000-7f75cdb12000 r-xp 00080000 08:12 1205250 /usr/lib/nvidia-367/libGLdispatch.so.07f75cdb12000-7f75cdd12000 ---p 000ba000 08:12 1205250 /usr/lib/nvidia-367/libGLdispatch.so.07f75cdd12000-7f75cdd21000 rw-p 000ba000 08:12 1205250 /usr/lib/nvidia-367/libGLdispatch.so.07f75cdd21000-7f75cdd41000 rw-p 00000000 00:00 0 7f75cdd41000-7f75cdd51000 r-xp 00000000 08:12 1205237 /usr/lib/nvidia-367/libGLX.so.07f75cdd51000-7f75cdf51000 ---p 00010000 08:12 1205237 /usr/lib/nvidia-367/libGLX.so.07f75cdf51000-7f75cdf52000 rw-p 00010000 08:12 1205237 /usr/lib/nvidia-367/libGLX.so.07f75cdf52000-7f75cdf72000 rw-p 00000000 00:00 0 7f75cdf72000-7f75cdfa3000 r-xp 00000000 08:12 1205244 /usr/lib/nvidia-367/libGL.so.1.0.07f75cdfa3000-7f75cdfd5000 r-xp 00031000 08:12 1205244 /usr/lib/nvidia-367/libGL.so.1.0.07f75cdfd5000-7f75cdfff000 r-xp 00063000 08:12 1205244 /usr/lib/nvidia-367/libGL.so.1.0.07f75cdfff000-7f75ce1ff000 ---p 0008d000 08:12 1205244 /usr/lib/nvidia-367/libGL.so.1.0.07f75ce1ff000-7f75ce200000 rw-p 0008d000 08:12 1205244 /usr/lib/nvidia-367/libGL.so.1.0.07f75ce200000-7f75ce201000 rw-p 00000000 00:00 0 7f75ce201000-7f75ce213000 r-xp 00000000 08:12 923036 /lib/x86_64-linux-gnu/libgpg-error.so.0.17.07f75ce213000-7f75ce413000 ---p 00012000 08:12 923036 /lib/x86_64-linux-gnu/libgpg-error.so.0.17.07f75ce413000-7f75ce414000 r--p 00012000 08:12 923036 /lib/x86_64-linux-gnu/libgpg-error.so.0.17.07f75ce414000-7f75ce415000 rw-p 00013000 08:12 923036 /lib/x86_64-linux-gnu/libgpg-error.so.0.17.07f75ce415000-7f75ce42c000 r-xp 00000000 08:12 923144 /lib/x86_64-linux-gnu/libresolv-2.23.so7f75ce42c000-7f75ce62c000 ---p 00017000 08:12 923144 /lib/x86_64-linux-gnu/libresolv-2.23.so7f75ce62c000-7f75ce62d000 r--p 00017000 08:12 923144 /lib/x86_64-linux-gnu/libresolv-2.23.so7f75ce62d000-7f75ce62e000 rw-p 00018000 08:12 923144 /lib/x86_64-linux-gnu/libresolv-2.23.so7f75ce62e000-7f75ce630000 rw-p 00000000 00:00 0 7f75ce630000-7f75ce646000 r-xp 00000000 08:12 923085 /lib/x86_64-linux-gnu/libnsl-2.23.so7f75ce646000-7f75ce845000 ---p 00016000 08:12 923085 /lib/x86_64-linux-gnu/libnsl-2.23.so7f75ce845000-7f75ce846000 r--p 00015000 08:12 923085 /lib/x86_64-linux-gnu/libnsl-2.23.so7f75ce846000-7f75ce847000 rw-p 00016000 08:12 923085 /lib/x86_64-linux-gnu/libnsl-2.23.so7f75ce847000-7f75ce849000 rw-p 00000000 00:00 0 7f75ce849000-7f75ce921000 r-xp 00000000 08:12 923032 /lib/x86_64-linux-gnu/libgcrypt.so.20.0.57f75ce921000-7f75ceb20000 ---p 000d8000 08:12 923032 /lib/x86_64-linux-gnu/libgcrypt.so.20.0.57f75ceb20000-7f75ceb21000 r--p 000d7000 08:12 923032 /lib/x86_64-linux-gnu/libgcrypt.so.20.0.57f75ceb21000-7f75ceb29000 rw-p 000d8000 08:12 923032 /lib/x86_64-linux-gnu/libgcrypt.so.20.0.57f75ceb29000-7f75ceb2a000 rw-p 00000000 00:00 0 7f75ceb2a000-7f75ceb49000 r-xp 00000000 08:12 923150 /lib/x86_64-linux-gnu/libselinux.so.17f75ceb49000-7f75ced48000 ---p 0001f000 08:12 923150 /lib/x86_64-linux-gnu/libselinux.so.17f75ced48000-7f75ced49000 r--p 0001e000 08:12 923150 /lib/x86_64-linux-gnu/libselinux.so.17f75ced49000-7f75ced4a000 rw-p 0001f000 08:12 923150 /lib/x86_64-linux-gnu/libselinux.so.17f75ced4a000-7f75ced4c000 rw-p 00000000 00:00 0 7f75ced4c000-7f75ced71000 r-xp 00000000 08:12 923164 /lib/x86_64-linux-gnu/libtinfo.so.5.97f75ced71000-7f75cef70000 ---p 00025000 08:12 923164 /lib/x86_64-linux-gnu/libtinfo.so.5.97f75cef70000-7f75cef74000 r--p 00024000 08:12 923164 /lib/x86_64-linux-gnu/libtinfo.so.5.97f75cef74000-7f75cef75000 rw-p 00028000 08:12 923164 /lib/x86_64-linux-gnu/libtinfo.so.5.97f75cef75000-7f75cf002000 r-xp 00000000 08:12 1190134 /usr/lib/x86_64-linux-gnu/libvorbisenc.so.2.0.117f75cf002000-7f75cf201000 ---p 0008d000 08:12 1190134 /usr/lib/x86_64-linux-gnu/libvorbisenc.so.2.0.117f75cf201000-7f75cf21d000 r--p 0008c000 08:12 1190134 /usr/lib/x86_64-linux-gnu/libvorbisenc.so.2.0.117f75cf21d000-7f75cf21e000 rw-p 000a8000 08:12 1190134 /usr/lib/x86_64-linux-gnu/libvorbisenc.so.2.0.117f75cf21e000-7f75cf28c000 r-xp 00000000 08:12 923121 /lib/x86_64-linux-gnu/libpcre.so.3.13.27f75cf28c000-7f75cf48c000 ---p 0006e000 08:12 923121 /lib/x86_64-linux-gnu/libpcre.so.3.13.27f75cf48c000-7f75cf48d000 r--p 0006e000 08:12 923121 /lib/x86_64-linux-gnu/libpcre.so.3.13.27f75cf48d000-7f75cf48e000 rw-p 0006f000 08:12 923121 /lib/x86_64-linux-gnu/libpcre.so.3.13.27f75cf48e000-7f75cf493000 r-xp 00000000 08:12 1188979 /usr/lib/x86_64-linux-gnu/libXdmcp.so.6.0.07f75cf493000-7f75cf692000 ---p 00005000 08:12 1188979 /usr/lib/x86_64-linux-gnu/libXdmcp.so.6.0.07f75cf692000-7f75cf693000 r--p 00004000 08:12 1188979 /usr/lib/x86_64-linux-gnu/libXdmcp.so.6.0.07f75cf693000-7f75cf694000 rw-p 00005000 08:12 1188979 /usr/lib/x86_64-linux-gnu/libXdmcp.so.6.0.07f75cf694000-7f75cf696000 r-xp 00000000 08:12 1188968 /usr/lib/x86_64-linux-gnu/libXau.so.6.0.07f75cf696000-7f75cf896000 ---p 00002000 08:12 1188968 /usr/lib/x86_64-linux-gnu/libXau.so.6.0.07f75cf896000-7f75cf897000 r--p 00002000 08:12 1188968 /usr/lib/x86_64-linux-gnu/libXau.so.6.0.07f75cf897000-7f75cf898000 rw-p 00003000 08:12 1188968 /usr/lib/x86_64-linux-gnu/libXau.so.6.0.07f75cf898000-7f75cf89d000 r-xp 00000000 08:12 1189062 /usr/lib/x86_64-linux-gnu/libasyncns.so.0.3.17f75cf89d000-7f75cfa9c000 ---p 00005000 08:12 1189062 /usr/lib/x86_64-linux-gnu/libasyncns.so.0.3.17f75cfa9c000-7f75cfa9d000 r--p 00004000 08:12 1189062 /usr/lib/x86_64-linux-gnu/libasyncns.so.0.3.17f75cfa9d000-7f75cfa9e000 rw-p 00005000 08:12 1189062 /usr/lib/x86_64-linux-gnu/libasyncns.so.0.3.17f75cfa9e000-7f75cfaa6000 r-xp 00000000 08:12 923178 /lib/x86_64-linux-gnu/libwrap.so.0.7.67f75cfaa6000-7f75cfca5000 ---p 00008000 08:12 923178 /lib/x86_64-linux-gnu/libwrap.so.0.7.67f75cfca5000-7f75cfca6000 r--p 00007000 08:12 923178 /lib/x86_64-linux-gnu/libwrap.so.0.7.67f75cfca6000-7f75cfca7000 rw-p 00008000 08:12 923178 /lib/x86_64-linux-gnu/libwrap.so.0.7.67f75cfca7000-7f75cfca8000 rw-p 00000000 00:00 0 7f75cfca8000-7f75cfcaf000 r-xp 00000000 08:12 1189808 /usr/lib/x86_64-linux-gnu/libogg.so.0.8.27f75cfcaf000-7f75cfeaf000 ---p 00007000 08:12 1189808 /usr/lib/x86_64-linux-gnu/libogg.so.0.8.27f75cfeaf000-7f75cfeb0000 r--p 00007000 08:12 1189808 /usr/lib/x86_64-linux-gnu/libogg.so.0.8.27f75cfeb0000-7f75cfeb1000 rw-p 00008000 08:12 1189808 /usr/lib/x86_64-linux-gnu/libogg.so.0.8.27f75cfeb1000-7f75cfedb000 r-xp 00000000 08:12 1190132 /usr/lib/x86_64-linux-gnu/libvorbis.so.0.4.87f75cfedb000-7f75d00db000 ---p 0002a000 08:12 1190132 /usr/lib/x86_64-linux-gnu/libvorbis.so.0.4.87f75d00db000-7f75d00dc000 r--p 0002a000 08:12 1190132 /usr/lib/x86_64-linux-gnu/libvorbis.so.0.4.87f75d00dc000-7f75d00dd000 rw-p 0002b000 08:12 1190132 /usr/lib/x86_64-linux-gnu/libvorbis.so.0.4.87f75d00dd000-7f75d011a000 r-xp 00000000 08:12 923143 /lib/x86_64-linux-gnu/libreadline.so.6.37f75d011a000-7f75d031a000 ---p 0003d000 08:12 923143 /lib/x86_64-linux-gnu/libreadline.so.6.37f75d031a000-7f75d031c000 r--p 0003d000 08:12 923143 /lib/x86_64-linux-gnu/libreadline.so.6.37f75d031c000-7f75d0322000 rw-p 0003f000 08:12 923143 /lib/x86_64-linux-gnu/libreadline.so.6.37f75d0322000-7f75d0323000 rw-p 00000000 00:00 0 7f75d0323000-7f75d0385000 r-xp 00000000 08:12 1190007 /usr/lib/x86_64-linux-gnu/libsndfile.so.1.0.257f75d0385000-7f75d0585000 ---p 00062000 08:12 1190007 /usr/lib/x86_64-linux-gnu/libsndfile.so.1.0.257f75d0585000-7f75d0587000 r--p 00062000 08:12 1190007 /usr/lib/x86_64-linux-gnu/libsndfile.so.1.0.257f75d0587000-7f75d0588000 rw-p 00064000 08:12 1190007 /usr/lib/x86_64-linux-gnu/libsndfile.so.1.0.257f75d0588000-7f75d058c000 rw-p 00000000 00:00 0 7f75d058c000-7f75d058f000 r-xp 00000000 08:12 1189915 /usr/lib/x86_64-linux-gnu/libpulse-simple.so.0.1.07f75d058f000-7f75d078f000 ---p 00003000 08:12 1189915 /usr/lib/x86_64-linux-gnu/libpulse-simple.so.0.1.07f75d078f000-7f75d0790000 r--p 00003000 08:12 1189915 /usr/lib/x86_64-linux-gnu/libpulse-simple.so.0.1.07f75d0790000-7f75d0791000 rw-p 00004000 08:12 1189915 /usr/lib/x86_64-linux-gnu/libpulse-simple.so.0.1.07f75d0791000-7f75d07d7000 r-xp 00000000 08:12 1189641 /usr/lib/x86_64-linux-gnu/libjack.so.0.1.07f75d07d7000-7f75d09d7000 ---p 00046000 08:12 1189641 /usr/lib/x86_64-linux-gnu/libjack.so.0.1.07f75d09d7000-7f75d09d9000 r--p 00046000 08:12 1189641 /usr/lib/x86_64-linux-gnu/libjack.so.0.1.07f75d09d9000-7f75d09da000 rw-p 00048000 08:12 1189641 /usr/lib/x86_64-linux-gnu/libjack.so.0.1.07f75d09da000-7f75d0ae9000 r-xp 00000000 08:12 923034 /lib/x86_64-linux-gnu/libglib-2.0.so.0.4800.17f75d0ae9000-7f75d0ce8000 ---p 0010f000 08:12 923034 /lib/x86_64-linux-gnu/libglib-2.0.so.0.4800.17f75d0ce8000-7f75d0ce9000 r--p 0010e000 08:12 923034 /lib/x86_64-linux-gnu/libglib-2.0.so.0.4800.17f75d0ce9000-7f75d0cea000 rw-p 0010f000 08:12 923034 /lib/x86_64-linux-gnu/libglib-2.0.so.0.4800.17f75d0cea000-7f75d0ceb000 rw-p 00000000 00:00 0 7f75d0ceb000-7f75d0cf6000 r-xp 00000000 08:12 1189650 /usr/lib/x86_64-linux-gnu/libjbig.so.07f75d0cf6000-7f75d0ef5000 ---p 0000b000 08:12 1189650 /usr/lib/x86_64-linux-gnu/libjbig.so.07f75d0ef5000-7f75d0ef6000 r--p 0000a000 08:12 1189650 /usr/lib/x86_64-linux-gnu/libjbig.so.07f75d0ef6000-7f75d0ef9000 rw-p 0000b000 08:12 1189650 /usr/lib/x86_64-linux-gnu/libjbig.so.07f75d0ef9000-7f75d0f1a000 r-xp 00000000 08:12 923059 /lib/x86_64-linux-gnu/liblzma.so.5.0.07f75d0f1a000-7f75d1119000 ---p 00021000 08:12 923059 /lib/x86_64-linux-gnu/liblzma.so.5.0.07f75d1119000-7f75d111a000 r--p 00020000 08:12 923059 /lib/x86_64-linux-gnu/liblzma.so.5.0.07f75d111a000-7f75d111b000 rw-p 00021000 08:12 923059 /lib/x86_64-linux-gnu/liblzma.so.5.0.07f75d111b000-7f75d1134000 r-xp 00000000 08:12 923182 /lib/x86_64-linux-gnu/libz.so.1.2.87f75d1134000-7f75d1333000 ---p 00019000 08:12 923182 /lib/x86_64-linux-gnu/libz.so.1.2.87f75d1333000-7f75d1334000 r--p 00018000 08:12 923182 /lib/x86_64-linux-gnu/libz.so.1.2.87f75d1334000-7f75d1335000 rw-p 00019000 08:12 923182 /lib/x86_64-linux-gnu/libz.so.1.2.87f75d1335000-7f75d133c000 r-xp 00000000 08:12 1189315 /usr/lib/x86_64-linux-gnu/libffi.so.6.0.47f75d133c000-7f75d153b000 ---p 00007000 08:12 1189315 /usr/lib/x86_64-linux-gnu/libffi.so.6.0.47f75d153b000-7f75d153c000 r--p 00006000 08:12 1189315 /usr/lib/x86_64-linux-gnu/libffi.so.6.0.47f75d153c000-7f75d153d000 rw-p 00007000 08:12 1189315 /usr/lib/x86_64-linux-gnu/libffi.so.6.0.47f75d153d000-7f75d1542000 r-xp 00000000 08:12 1188983 /usr/lib/x86_64-linux-gnu/libXfixes.so.3.1.07f75d1542000-7f75d1741000 ---p 00005000 08:12 1188983 /usr/lib/x86_64-linux-gnu/libXfixes.so.3.1.07f75d1741000-7f75d1742000 r--p 00004000 08:12 1188983 /usr/lib/x86_64-linux-gnu/libXfixes.so.3.1.07f75d1742000-7f75d1743000 rw-p 00005000 08:12 1188983 /usr/lib/x86_64-linux-gnu/libXfixes.so.3.1.07f75d1743000-7f75d174c000 r-xp 00000000 08:12 1189001 /usr/lib/x86_64-linux-gnu/libXrender.so.1.3.07f75d174c000-7f75d194b000 ---p 00009000 08:12 1189001 /usr/lib/x86_64-linux-gnu/libXrender.so.1.3.07f75d194b000-7f75d194c000 r--p 00008000 08:12 1189001 /usr/lib/x86_64-linux-gnu/libXrender.so.1.3.07f75d194c000-7f75d194d000 rw-p 00009000 08:12 1189001 /usr/lib/x86_64-linux-gnu/libXrender.so.1.3.07f75d194d000-7f75d196e000 r-xp 00000000 08:12 1190217 /usr/lib/x86_64-linux-gnu/libxcb.so.1.1.07f75d196e000-7f75d1b6d000 ---p 00021000 08:12 1190217 /usr/lib/x86_64-linux-gnu/libxcb.so.1.1.07f75d1b6d000-7f75d1b6e000 r--p 00020000 08:12 1190217 /usr/lib/x86_64-linux-gnu/libxcb.so.1.1.07f75d1b6e000-7f75d1b6f000 rw-p 00021000 08:12 1190217 /usr/lib/x86_64-linux-gnu/libxcb.so.1.1.07f75d1b6f000-7f75d1b82000 r-xp 00000000 08:12 922988 /lib/x86_64-linux-gnu/libbsd.so.0.8.27f75d1b82000-7f75d1d81000 ---p 00013000 08:12 922988 /lib/x86_64-linux-gnu/libbsd.so.0.8.27f75d1d81000-7f75d1d82000 r--p 00012000 08:12 922988 /lib/x86_64-linux-gnu/libbsd.so.0.8.27f75d1d82000-7f75d1d83000 rw-p 00013000 08:12 922988 /lib/x86_64-linux-gnu/libbsd.so.0.8.27f75d1d83000-7f75d1d84000 rw-p 00000000 00:00 0 7f75d1d84000-7f75d1dce000 r-xp 00000000 08:12 923008 /lib/x86_64-linux-gnu/libdbus-1.so.3.14.67f75d1dce000-7f75d1fce000 ---p 0004a000 08:12 923008 /lib/x86_64-linux-gnu/libdbus-1.so.3.14.67f75d1fce000-7f75d1fcf000 r--p 0004a000 08:12 923008 /lib/x86_64-linux-gnu/libdbus-1.so.3.14.67f75d1fcf000-7f75d1fd0000 rw-p 0004b000 08:12 923008 /lib/x86_64-linux-gnu/libdbus-1.so.3.14.67f75d1fd0000-7f75d2049000 r-xp 00000000 08:12 2884 /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-8.0.so7f75d2049000-7f75d2248000 ---p 00079000 08:12 2884 /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-8.0.so7f75d2248000-7f75d2249000 r--p 00078000 08:12 2884 /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-8.0.so7f75d2249000-7f75d224a000 rw-p 00079000 08:12 2884 /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-8.0.so7f75d224a000-7f75d2254000 r-xp 00000000 08:12 923051 /lib/x86_64-linux-gnu/libjson-c.so.2.0.07f75d2254000-7f75d2453000 ---p 0000a000 08:12 923051 /lib/x86_64-linux-gnu/libjson-c.so.2.0.07f75d2453000-7f75d2454000 r--p 00009000 08:12 923051 /lib/x86_64-linux-gnu/libjson-c.so.2.0.07f75d2454000-7f75d2455000 rw-p 0000a000 08:12 923051 /lib/x86_64-linux-gnu/libjson-c.so.2.0.07f75d2455000-7f75d2473000 r-xp 00000000 08:12 1189697 /usr/lib/x86_64-linux-gnu/libmad.so.0.2.17f75d2473000-7f75d2672000 ---p 0001e000 08:12 1189697 /usr/lib/x86_64-linux-gnu/libmad.so.0.2.17f75d2672000-7f75d2673000 r--p 0001d000 08:12 1189697 /usr/lib/x86_64-linux-gnu/libmad.so.0.2.17f75d2673000-7f75d2674000 rw-p 0001e000 08:12 1189697 /usr/lib/x86_64-linux-gnu/libmad.so.0.2.17f75d2674000-7f75d26e7000 r-xp 00000000 08:12 1188904 /usr/lib/x86_64-linux-gnu/libFLAC.so.8.3.07f75d26e7000-7f75d28e7000 ---p 00073000 08:12 1188904 /usr/lib/x86_64-linux-gnu/libFLAC.so.8.3.07f75d28e7000-7f75d28e8000 r--p 00073000 08:12 1188904 /usr/lib/x86_64-linux-gnu/libFLAC.so.8.3.07f75d28e8000-7f75d28e9000 rw-p 00074000 08:12 1188904 /usr/lib/x86_64-linux-gnu/libFLAC.so.8.3.07f75d28e9000-7f75d28f0000 r-xp 00000000 08:12 1190136 /usr/lib/x86_64-linux-gnu/libvorbisfile.so.3.3.77f75d28f0000-7f75d2af0000 ---p 00007000 08:12 1190136 /usr/lib/x86_64-linux-gnu/libvorbisfile.so.3.3.77f75d2af0000-7f75d2af1000 r--p 00007000 08:12 1190136 /usr/lib/x86_64-linux-gnu/libvorbisfile.so.3.3.77f75d2af1000-7f75d2af2000 rw-p 00008000 08:12 1190136 /usr/lib/x86_64-linux-gnu/libvorbisfile.so.3.3.77f75d2af2000-7f75d2b47000 r-xp 00000000 08:12 1202428 /usr/lib/x86_64-linux-gnu/libfluidsynth.so.1.5.27f75d2b47000-7f75d2d47000 ---p 00055000 08:12 1202428 /usr/lib/x86_64-linux-gnu/libfluidsynth.so.1.5.27f75d2d47000-7f75d2d48000 r--p 00055000 08:12 1202428 /usr/lib/x86_64-linux-gnu/libfluidsynth.so.1.5.27f75d2d48000-7f75d2d4a000 rw-p 00056000 08:12 1202428 /usr/lib/x86_64-linux-gnu/libfluidsynth.so.1.5.27f75d2d4a000-7f75d2db8000 rw-p 00000000 00:00 0 7f75d2db8000-7f75d2e02000 r-xp 00000000 08:12 1189717 /usr/lib/x86_64-linux-gnu/libmodplug.so.1.0.07f75d2e02000-7f75d3002000 ---p 0004a000 08:12 1189717 /usr/lib/x86_64-linux-gnu/libmodplug.so.1.0.07f75d3002000-7f75d3003000 r--p 0004a000 08:12 1189717 /usr/lib/x86_64-linux-gnu/libmodplug.so.1.0.07f75d3003000-7f75d3004000 rw-p 0004b000 08:12 1189717 /usr/lib/x86_64-linux-gnu/libmodplug.so.1.0.07f75d3004000-7f75d3143000 rw-p 00000000 00:00 0 7f75d3143000-7f75d319c000 r-xp 00000000 08:12 1190161 /usr/lib/x86_64-linux-gnu/libwebp.so.5.0.47f75d319c000-7f75d339c000 ---p 00059000 08:12 1190161 /usr/lib/x86_64-linux-gnu/libwebp.so.5.0.47f75d339c000-7f75d339d000 r--p 00059000 08:12 1190161 /usr/lib/x86_64-linux-gnu/libwebp.so.5.0.47f75d339d000-7f75d339f000 rw-p 0005a000 08:12 1190161 /usr/lib/x86_64-linux-gnu/libwebp.so.5.0.47f75d339f000-7f75d340e000 r-xp 00000000 08:12 1190077 /usr/lib/x86_64-linux-gnu/libtiff.so.5.2.47f75d340e000-7f75d360e000 ---p 0006f000 08:12 1190077 /usr/lib/x86_64-linux-gnu/libtiff.so.5.2.47f75d360e000-7f75d360f000 r--p 0006f000 08:12 1190077 /usr/lib/x86_64-linux-gnu/libtiff.so.5.2.47f75d360f000-7f75d3612000 rw-p 00070000 08:12 1190077 /usr/lib/x86_64-linux-gnu/libtiff.so.5.2.47f75d3612000-7f75d3669000 r-xp 00000000 08:12 1189654 /usr/lib/x86_64-linux-gnu/libjpeg.so.8.0.27f75d3669000-7f75d3869000 ---p 00057000 08:12 1189654 /usr/lib/x86_64-linux-gnu/libjpeg.so.8.0.27f75d3869000-7f75d386a000 r--p 00057000 08:12 1189654 /usr/lib/x86_64-linux-gnu/libjpeg.so.8.0.27f75d386a000-7f75d386b000 rw-p 00058000 08:12 1189654 /usr/lib/x86_64-linux-gnu/libjpeg.so.8.0.27f75d386b000-7f75d388f000 r-xp 00000000 08:12 923133 /lib/x86_64-linux-gnu/libpng12.so.0.54.07f75d388f000-7f75d3a8e000 ---p 00024000 08:12 923133 /lib/x86_64-linux-gnu/libpng12.so.0.54.07f75d3a8e000-7f75d3a8f000 r--p 00023000 08:12 923133 /lib/x86_64-linux-gnu/libpng12.so.0.54.07f75d3a8f000-7f75d3a90000 rw-p 00024000 08:12 923133 /lib/x86_64-linux-gnu/libpng12.so.0.54.07f75d3a90000-7f75d3b34000 r-xp 00000000 08:12 1189371 /usr/lib/x86_64-linux-gnu/libfreetype.so.6.12.17f75d3b34000-7f75d3d33000 ---p 000a4000 08:12 1189371 /usr/lib/x86_64-linux-gnu/libfreetype.so.6.12.17f75d3d33000-7f75d3d39000 r--p 000a3000 08:12 1189371 /usr/lib/x86_64-linux-gnu/libfreetype.so.6.12.17f75d3d39000-7f75d3d3a000 rw-p 000a9000 08:12 1189371 /usr/lib/x86_64-linux-gnu/libfreetype.so.6.12.17f75d3d3a000-7f75d3d41000 r-xp 00000000 08:12 923146 /lib/x86_64-linux-gnu/librt-2.23.so7f75d3d41000-7f75d3f40000 ---p 00007000 08:12 923146 /lib/x86_64-linux-gnu/librt-2.23.so7f75d3f40000-7f75d3f41000 r--p 00006000 08:12 923146 /lib/x86_64-linux-gnu/librt-2.23.soAborted (core dumped)

delete[] myBullets;

I don't see where you initialize myBullets in the constructor.

If you convert to using std::vector instead of rolling your own version of the same thing, does the problem still occur?

Stephen M. Webb
Professional Free Software Developer

As Bregma points out you are not initialising myBullets so calling delete on it will not end well for you.

void shoot(const int cursorX, const int cursorY)
{
  //Update timeStep
  if (!timeStepUpdatedThisLoop) updateTimeStep();
  if (!timeStep) return;
 
  //Calculate mouse position relative to level
  int relativeX = mylevel->texture.getW()-cursorX;
  int relativeY = mylevel->texture.getH()-cursorY;
 
  //Create a new bullet object in the bullet array
  Bullet** temp = new Bullet*[++myBullets_size];
  for (int i{}; i<myBullets_size-1; ++i)
  {
    temp[i]=myBullets[i];
  }
  temp[myBullets_size-1] = new Bullet(x,y,cursorX,cursorY,*mylevel);
  temp[myBullets_size-1]->texture.assign(texture.getCamera());
}

You have a memory leak right there too. 'temp' is just lost.

Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.

Advertisement

the owner variable isn't there anymore, and I think that only now have I decided to start using an array of pointers to Bullet's scattered around in the heap instead of the Bullet's being laid out sequentially in memory

You still have this problem that I mentioned with aggressiveEntity.h.

I can't see anywhere in aggressiveEntity.h where you assign myBullets. Since it also isn't initialised to null, it means that it is pointing to random data and potentially will crash when you try to deference the pointer (which will happen in the update loop).

Steven Yau
[Blog] [Portfolio]

This topic is closed to new replies.

Advertisement