Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[models] Crash when loading .vox model on Android with SIGSEGV error #3098

Closed
Bigfoot71 opened this issue Jun 4, 2023 · 39 comments
Closed
Labels
external This issue depends on external lib

Comments

@Bigfoot71
Copy link
Contributor

Bigfoot71 commented Jun 4, 2023

I encountered a crash issue when attempting to load a .vox model on Android using LoadModel(). The application crashes with the following log:

2023-06-04 15:01:04.887 30219-30369 libc com.bigfoot.raymob A Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x1205b941 in tid 30369 (Thread-7), pid 30219 (.bigfoot.raymob)
2023-06-04 15:01:05.065 30858-30858 DEBUG pid-30858 A pid: 30219, tid: 30369, name: Thread-7 >>> com.bigfoot.raymob <<<
2023-06-04 15:01:05.080 30858-30858 DEBUG pid-30858 A #00 pc 000852b4 /data/app/com.bigfoot.raymob-u7jUzwaU1Sz71d6mrGOUhQ==/base.apk!libraymob.so (offset 0x723000) (Vox_LoadFromMemory+144) (BuildId: 05f2523c1f15f8756fe8c105210d0418ed38d02a)

The crash occurs in the function Vox_LoadFromMemory within vox_loader.h. It seems to be a segmentation fault (SIGSEGV) with code 1 (SEGV_MAPERR).

Steps to Reproduce:

  1. Build and run the raylib application on an Android device.
  2. Attempt to load a .vox model using the LoadModel / Vox_LoadFromMemory function.

Expected Behavior:
The .vox model should be loaded successfully without any crashes.

Actual Behavior:
The application crashes with a SIGSEGV error when attempting to load the .vox model.

Reproducible Demo: Source / APK / EXE - (Dropbox)

Additional Information:

  • Android device: Xiaomi Redmi A9 [M2006C3LG]
  • Android version: Android 10
  • raylib version: 4.5 / 4.6 dev

I would greatly appreciate any assistance in resolving this issue. Let me know if any further information is required.

@raysan5 raysan5 added the external This issue depends on external lib label Jun 4, 2023
@raysan5
Copy link
Owner

raysan5 commented Jun 4, 2023

This issue seems related to an external library, created by a contributor so, technically the issue does not belong to this repo but the repo of the creator of the library.

I'm afraid the maintenance and support of vox_loader.h should be in charge or the creator of the library, not raylib developer.

This is a common problem with that kind of contributions... who takes care of the related issues?

@Bigfoot71
Copy link
Contributor Author

It's problematic that the person who seems to be the originator of this code didn't make a repository for this work. It seems to only exist here.

Nevertheless, I was able to isolate the issue, and it appears to stem from this while loop in the Vox_LoadFromMemory function.
https://github.com/raysan5/raylib/blob/master/src/external/vox_loader.h#L579

If I remove the conditional part related to the color, there are no more crashes. That's the only notable thing I noticed, although it could be related to other factors. However, if we trust the logs I received, the error indeed seems to occur in Vox_LoadFromMemory and not in the other functions called by it.

I apologize for not being able to provide more precise information. It's quite complicated and very cumbersome for me to debug this code with my equipment, unfortunately.

@raysan5
Copy link
Owner

raysan5 commented Jun 4, 2023

@Bigfoot71 No worries, I took a quick look to the code and it's quite clean and organized, also it's relatively small.

Maybe @fxgenstudio can take a look to this issue?

Also checked for updated specs but I couldn't find much info, only the v150 specs and the extension specs.

@Bigfoot71
Copy link
Contributor Author

Bigfoot71 commented Jun 5, 2023

I have sent an email hoping that it is received.

Otherwise, considering the issue occurring only on Android without any apparent reason, I thought about disabling compiler optimizations, but the result remains the same.

@fxgenstudio
Copy link
Contributor

Hi,
I'll test on Android this week. You load what Vox model ? It 's not an out of memory problem ?

@Bigfoot71
Copy link
Contributor Author

I have tested many different models obtained from the internet, including the ones I used in my reproducible example. They all work on Linux/Windows but crash on Android. However, they work on Android if I convert them to GLB or OBJ.

I thought about memory as a possible issue, but according to the Android Studio profiler, there is no memory spike at the time of the crash. On the contrary, memory usage decreases just before the crash because I deallocate other things before loading the models.

Moreover, I am far from the total limit of 256MB, there is only the stack occupation that I cannot see. I can only see its total size, which is 60KB (I mention this because the total of the stack never changes, which makes me think that it refers to the total allocated size).

I also tested by adding android:largeHeap="true" in the manifest, but the crash still occurs.

Furthermore, the crash happens as soon as the first model is loaded, even if it is a small model (i.e., <20 voxels).

VOXS.zip - (15 models)

@fxgenstudio
Copy link
Contributor

fxgenstudio commented Jun 5, 2023

You have an example for visual studio and android ?
Or how to build your project from androidstudio ?

@Bigfoot71
Copy link
Contributor Author

No, the example I provided will not work with Android Studio. You need to use the Makefile with the following command:
Linux: make PLATFORM=PLATFORM_ANDROID ANDROID_ARCH=<your arch>
Windows: mingw32-make PLATFORM=PLATFORM_ANDROID ANDROID_ARCH=<your arch>

However, you may need to modify the Makefiles a bit to make it work on your end.

But I have quickly created an Android Studio project for you if you prefer.
I have included a Readme file with all the information, it should automatically open in Android Studio.

VoxTest for Android Studio

If you need any further information, please don't hesitate to ask!

@fxgenstudio
Copy link
Contributor

Thanks for your Android Studio project.
The project work with my Redmi11Pro.

VoxTest_060623.zip

I'll try with an other mobile.

@Bigfoot71
Copy link
Contributor Author

Strange, so it would strongly resemble a memory overflow problem, yet the profiler does not indicate anything at this level on my side.

Maybe the information is relevant, my device architecture is armeabi-v7a

@raysan5
Copy link
Owner

raysan5 commented Jun 6, 2023

@Bigfoot71 @fxgenstudio Did you try debugging the code to find the exact point where it crashes? Maybe it fails on memory allocation under some specific circunstances of maybe on file access.

@Bigfoot71
Copy link
Contributor Author

Sorry for not having shared all the logs on this subject here, I think we can rule out the file access problem, in my case the crash does occur in Vox_LoadFromMemory after the file has been loaded successfully :

2023-06-03 22:00:11.521  6779-6885  raylib                  com.bigfoot.raymob                   I  FILEIO: [models/player/1.vox] File loaded successfully
2023-06-03 22:00:12.484  6779-6885  libc                    com.bigfoot.raymob                   A  Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x125f6a91 in tid 6885 (Thread-7), pid 6779 (.bigfoot.raymob)

@raysan5
Copy link
Owner

raysan5 commented Jun 6, 2023

@Bigfoot71 Did you rebuild raylib for Android using the same compiler as your app? Did you generate a separate dynamic library for raylib and your app or is it a single library (raylib linked statically)?

@Bigfoot71
Copy link
Contributor Author

Bigfoot71 commented Jun 6, 2023

Yes, raylib has been recompiled dozens of times as well as the project and the minimal test, with the same version of clang each time (whether on Linux or Windows which do not have the same setup), the result is always the same. And raylib is statically linked.

Regarding the fact of finding the exact point where it crashes in the library, it would be necessary to try by compiling raylib directly with the project to be able to have access to more information, I have already tried, it was not easy and the information obtained was not very revealing. I'll try tonight to rewrite the Android project's CMakeList file to do this, hope it makes it easier and can give more information when debugging.

@fxgenstudio
Copy link
Contributor

You could try my apk ?
debug.zip

VoxTest.mp4

@Bigfoot71
Copy link
Contributor Author

Sorry I can't, the APK is compiled for arm64-v8a, and the only device I have available is armeabi-v7a as I mentioned before, unfortunately. I still tried, but I'm getting an error with adb install.

@fxgenstudio
Copy link
Contributor

From Android studio it also works for my Redmi9 (M2004J19AG)

@Bigfoot71
Copy link
Contributor Author

And you haven't made any changes? I don't know what to say, I've tried dozens of times, I always come across the same error, even with the most minimal example possible.

@fxgenstudio
Copy link
Contributor

No changes, I use android studio 2022.2.1 with your project.
I'm under Win11.
It could be interesting to trace app execution in debug mode with raylib source code. In order to see where that crash.

@Bigfoot71
Copy link
Contributor Author

Just like me for Android Studio, the Flamingo version.

However, something really strange happened. While I was running all the tests one last time to get all the logs, I thought I could also record a video of the profiler and resource consumption. So, I clicked on "Profile 'app' with complete data," it recompiled the app, and it opened without crashing with the models for the first time!

So, I tried again, still using "Profile 'app' with complete data," and it worked fine that way.
Then, I ran the app again with the normal "run" button, it recompiled, and crashed again!
After that, I tried it with "Profile 'app' with low overhead," and it crashed as well.

I would like to remind you that the crash also happens in release mode with the minimalist Makefile that I provided in my example.

What do you think could explain this?

So far, I haven't been able to get better logs than this, despite the fact that raylib is compiled with all debug symbols, optimizations disabled, etc:

2023-06-07 00:55:47.893 26381-26441 raylib                  com.bigfoot.raymob                   I  FILEIO: [1.vox] File loaded successfully
2023-06-07 00:55:47.894 26381-26441 libc                    com.bigfoot.raymob                   A  Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x13144265 in tid 26441 (.bigfoot.raymob), pid 26381 (.bigfoot.raymob)
2023-06-07 00:55:47.994 26460-26460 DEBUG                   pid-26460                            A  pid: 26381, tid: 26441, name: .bigfoot.raymob  >>> com.bigfoot.raymob <<<
2023-06-07 00:55:47.999 26460-26460 DEBUG                   pid-26460                            A        #00 pc 0008a304  /data/app/com.bigfoot.raymob-bGsbia4SkvMH0tUMcTuvmw==/base.apk!libraymob.so (offset 0x41000) (Vox_LoadFromMemory+228) (BuildId: 1bdd0cdad14882d243332b8dfcde36cebfa97c3b)
2023-06-07 00:55:47.999 26460-26460 DEBUG                   pid-26460                            A        #01 pc 000a8d14  /data/app/com.bigfoot.raymob-bGsbia4SkvMH0tUMcTuvmw==/base.apk!libraymob.so (offset 0x41000) (BuildId: 1bdd0cdad14882d243332b8dfcde36cebfa97c3b)
2023-06-07 00:55:47.999 26460-26460 DEBUG                   pid-26460                            A        #02 pc 000a4810  /data/app/com.bigfoot.raymob-bGsbia4SkvMH0tUMcTuvmw==/base.apk!libraymob.so (offset 0x41000) (LoadModel+284) (BuildId: 1bdd0cdad14882d243332b8dfcde36cebfa97c3b)
2023-06-07 00:55:47.999 26460-26460 DEBUG                   pid-26460                            A        #03 pc 0000f8c5  /data/app/com.bigfoot.raymob-bGsbia4SkvMH0tUMcTuvmw==/base.apk!libraymob.so (offset 0x41000) (main+332) (BuildId: 1bdd0cdad14882d243332b8dfcde36cebfa97c3b)
2023-06-07 00:55:47.999 26460-26460 DEBUG                   pid-26460                            A        #04 pc 00029040  /data/app/com.bigfoot.raymob-bGsbia4SkvMH0tUMcTuvmw==/base.apk!libraymob.so (offset 0x41000) (android_main+136) (BuildId: 1bdd0cdad14882d243332b8dfcde36cebfa97c3b)
2023-06-07 00:55:48.000 26460-26460 DEBUG                   pid-26460                            A        #05 pc 00010b61  /data/app/com.bigfoot.raymob-bGsbia4SkvMH0tUMcTuvmw==/base.apk!libraymob.so (offset 0x41000) (BuildId: 1bdd0cdad14882d243332b8dfcde36cebfa97c3b)
2023-06-07 00:55:49.001 26381-26427 .bigfoot.raymo          com.bigfoot.raymob                   I  ProcessProfilingInfo new_methods=0 is saved saved_to_disk=0 resolve_classes_delay=8000
2023-06-07 00:55:50.030 26381-26381 threaded_app            com.bigfoot.raymob                   V  Pause: 0xda6a0140
---------------------------- PROCESS ENDED (26381) for package com.bigfoot.raymob ----------------------------
2023-06-07 00:55:50.166  1223-1356  InputDispatcher         system_server                        E  channel '563591d com.bigfoot.raymob/com.bigfoot.raymob.NativeLoader (server)' ~ Channel is unrecoverably broken and will be disposed!
(lldb) bt
* thread #21, name = '.bigfoot.raymob', stop reason = breakpoint 1.1
  * frame #0: 0xee135354 libart.so`art_sigsegv_fault
    frame #1: 0xee135692 libart.so`art::FaultManager::HandleFault(int, siginfo*, void*) + 230
    frame #2: 0xef734cc8 libc.so`sigprocmask + 52
    frame #3: 0xef783260 libc.so`ru_reseed + 4

app-disassembly.txt

@chriscamacho
Copy link
Contributor

this smells like stack corruption

valgrind is your friend here...

bare in mind that its not impossible it could be inducing a crash in a 3rd party (system) library, which you might not have the debug info for installed...

@Bigfoot71
Copy link
Contributor Author

Bigfoot71 commented Jun 7, 2023

So I first tried to compile raylib and the test project with -fsanitize=address, but due to more and more error messages, I learned that the device needed to be rooted. Unfortunately, my PC is not powerful enough to launch an emulator, and given the situation, it would have a great chance of working on it...

I looked into HWASan, but again, it requires a flashed device. Then I compiled Valgrind and followed the instructions to use it on Android until I realized that the device also needed to be rooted.

Since this is the only phone I have available, and it's my personal phone, I don't really want to root it.

If I'm the only one who can reproduce this behavior, and it's impossible for me to learn more about it in the current state, should we close this issue?

If that's the case, morally, I will absolutely avoid using vox files on Android.
(It's a shame because they had quite a few advantages in my case..)

@chriscamacho
Copy link
Contributor

try making a simple test case for the pc can you induce it to crash? if so valgrind is your friend!

@raysan5
Copy link
Owner

raysan5 commented Jun 7, 2023

@Bigfoot71 I'm afraid it's very difficult to reproduce and properly track the issue outside of your test environment. I reviewed Vox_LoadFromMemory() and, despite I'm a bit concerned about some code design approaches, I couldn't find any noticeable issue. The only possible solution is debugging the code to detect the exact crash point inside Vox_LoadFromMemory().

@Bigfoot71
Copy link
Contributor Author

@chriscamacho I'm afraid reproducing the exact same issue on a PC might not be that simple, but I'll think about it.
@raysan5 That's exactly what I'm thinking too. At the moment, it is impossible to obtain any more information than what I have provided.

I'll search for a way to do it without a rooted device. There must be a way. If anyone has an idea...
Anyway, thank you for your advice! I'll come back when I have any updates.

@raysan5
Copy link
Owner

raysan5 commented Jun 7, 2023

@Bigfoot71 On those situations, a solution I used in the past was printing traces all the time for every sensible line of code from the function involved. You should add those traces to Vox_LoadFromMemory(), recompile and check output to see the exact line where things crash.

@Bigfoot71
Copy link
Contributor Author

Bigfoot71 commented Jun 7, 2023

@raysan5 You're right, I'm stupid. I should have done it a long time ago...

So, I did three tests:

  1. It crashed after about +/- 50 iterations in the first while loop maybe at the moment of memcpy (line 582).

  2. Then I added iteration counting, and it crashed during the condition checks SIZE | XYZI | RGBA, probably due to strcmp (example line), but after over a thousand iterations.

  3. I modified one of the log outputs, recompiled, and it crashed again maybe at the memcpy level after only 17 iterations... (line 582).

I'm including the function used with the logs from the last test.
I can redo the tests if needed.

Vox_LoadFromMemory_debug.c.txt
third-test-logs.txt

Edit: I also tried what had worked twice yesterday, which was to launch with Profile 'app' with complete data but it's not working anymore now, it crashes again. Here's the graph, just in case. (in fact it works half the time)

2023-06-07-16-29-53.mp4

@raysan5
Copy link
Owner

raysan5 commented Jun 7, 2023

@Bigfoot71 Thanks for the test and the additional info! Could you try just moving char szChunkName[5]; out of the while loop and define it as unsigned char szChunkName[8] = { 0 };, just to make sure the type is unsigned and also data is aligned in memory (avoiding any padding issue on stack memory, despite being a very unprobable issue).

Oh, and also replace strcmp(szChunkName, "xxxx") == 0 by strncmp(szChunkName, "xxxx", 4) == 0.

EDIT: Looking now more carefully to the code, I think the issue is actually that char szChunkName[5]; is not properly initialized, so szChunkName[4] could not be \0 and strcmp() fails because it can not detect the end of the line and checks beyond memory limits. Try just setting char szChunkName[5] = { 0 };

If you use the first solution I proposed, make sure to set szChunkName[4] = '\0'; at the beginning of the while loop (or just memset(szChunkName, 0, 8) to make sure it's reseted.

@bztsrc
Copy link

bztsrc commented Jun 7, 2023

If that's the case, morally, I will absolutely avoid using vox files on Android.
(It's a shame because they had quite a few advantages in my case..)

If the advantage that you're talking about is being a voxel format, then you might want to give a try to Model3D. It is supported by raylib, and the repo contains a command line tool which can convert .vox files into .m3d files. Unlike GLB and OBJ, it's capable of storing voxel data, so you would still have that advantage (voxel info is automatically triangulated into a mesh on load). Further advantage that a .m3d file is much smaller than .vox for the same model.

Not a real solution, but hope this helps,
bzt

@Bigfoot71
Copy link
Contributor Author

Bigfoot71 commented Jun 7, 2023

@raysan5 I tried the solutions you suggested.

The first one:

	unsigned char szChunkName[8] = { 0 };

	while (fileDataPtr < endfileDataPtr)
	{

		szChunkName[4] = '\0';
		memcpy(szChunkName, fileDataPtr, 4);
		szChunkName[4] = 0;
		fileDataPtr += 4;
		
		[...]
		
		if (strncmp(szChunkName, "SIZE", 4) == 0)
		
		[...]

Its result, it seems to have crashed just after memcpy but without having entered one of the conditions after a hundred iterations:

2023-06-07 19:06:15.178 28271-28367 DEBUG - Vo...omMemory() com.bigfoot.raymob                   I  `memcpy(szChunkName, fileDataPtr, 4)` IS DONE
2023-06-07 19:06:15.195 28271-28367 libc                    com.bigfoot.raymob                   A  Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x135179a9 in tid 28367 (.bigfoot.raymob), pid 28271 (.bigfoot.raymob)
2023-06-07 19:06:15.302 28373-28373 DEBUG                   pid-28373                            A  pid: 28271, tid: 28367, name: .bigfoot.raymob  >>> com.bigfoot.raymob <<<
2023-06-07 19:06:15.308 28373-28373 DEBUG                   pid-28373                            A        #00 pc 0008a384  /data/app/com.bigfoot.raymob-9UkfoTic88xfmuCLsu_19w==/base.apk!libraymob.so (offset 0x40000) (Vox_LoadFromMemory+372) (BuildId: 6f6a305721fe9499f0676d3ee4d7dbb414c82db2)
2023-06-07 19:06:15.309 28373-28373 DEBUG                   pid-28373                            A        #01 pc 000a8fac  /data/app/com.bigfoot.raymob-9UkfoTic88xfmuCLsu_19w==/base.apk!libraymob.so (offset 0x40000) (BuildId: 6f6a305721fe9499f0676d3ee4d7dbb414c82db2)
2023-06-07 19:06:15.309 28373-28373 DEBUG                   pid-28373                            A        #02 pc 000a4aa8  /data/app/com.bigfoot.raymob-9UkfoTic88xfmuCLsu_19w==/base.apk!libraymob.so (offset 0x40000) (LoadModel+284) (BuildId: 6f6a305721fe9499f0676d3ee4d7dbb414c82db2)
2023-06-07 19:06:15.309 28373-28373 DEBUG                   pid-28373                            A        #03 pc 0000f8b9  /data/app/com.bigfoot.raymob-9UkfoTic88xfmuCLsu_19w==/base.apk!libraymob.so (offset 0x40000) (main+320) (BuildId: 6f6a305721fe9499f0676d3ee4d7dbb414c82db2)
2023-06-07 19:06:15.309 28373-28373 DEBUG                   pid-28373                            A        #04 pc 00029030  /data/app/com.bigfoot.raymob-9UkfoTic88xfmuCLsu_19w==/base.apk!libraymob.so (offset 0x40000) (android_main+136) (BuildId: 6f6a305721fe9499f0676d3ee4d7dbb414c82db2)
2023-06-07 19:06:15.309 28373-28373 DEBUG                   pid-28373                            A        #05 pc 00010b51  /data/app/com.bigfoot.raymob-9UkfoTic88xfmuCLsu_19w==/base.apk!libraymob.so (offset 0x40000) (BuildId: 6f6a305721fe9499f0676d3ee4d7dbb414c82db2)

I also tried replacing szChunkName[4] = '\0' with memset(szChunkName, 0, 8) and it crashed after dozens iterations at the memcpy level (sorry , I had removed the display of iterations without doing it on purpose):

2023-06-07 19:17:19.301 29974-30092 DEBUG - Vo...omMemory() com.bigfoot.raymob                   I  NO MATCH FOUND
2023-06-07 19:17:19.307 29974-30092 libc                    com.bigfoot.raymob                   A  Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x134c4bd1 in tid 30092 (.bigfoot.raymob), pid 29974 (.bigfoot.raymob)
2023-06-07 19:17:19.432 30100-30100 DEBUG                   pid-30100                            A  pid: 29974, tid: 30092, name: .bigfoot.raymob  >>> com.bigfoot.raymob <<<
2023-06-07 19:17:19.437 30100-30100 DEBUG                   pid-30100                            A        #00 pc 0008a3a4  /data/app/com.bigfoot.raymob-C4cpo3DmbcWDyt4Gn3_5yA==/base.apk!libraymob.so (offset 0x41000) (Vox_LoadFromMemory+404) (BuildId: 9478e2f21e71debedf831a720d64390b20bce528)
2023-06-07 19:17:19.437 30100-30100 DEBUG                   pid-30100                            A        #01 pc 000a8fdc  /data/app/com.bigfoot.raymob-C4cpo3DmbcWDyt4Gn3_5yA==/base.apk!libraymob.so (offset 0x41000) (BuildId: 9478e2f21e71debedf831a720d64390b20bce528)
2023-06-07 19:17:19.437 30100-30100 DEBUG                   pid-30100                            A        #02 pc 000a4ad8  /data/app/com.bigfoot.raymob-C4cpo3DmbcWDyt4Gn3_5yA==/base.apk!libraymob.so (offset 0x41000) (LoadModel+284) (BuildId: 9478e2f21e71debedf831a720d64390b20bce528)
2023-06-07 19:17:19.437 30100-30100 DEBUG                   pid-30100                            A        #03 pc 0000f8b9  /data/app/com.bigfoot.raymob-C4cpo3DmbcWDyt4Gn3_5yA==/base.apk!libraymob.so (offset 0x41000) (main+320) (BuildId: 9478e2f21e71debedf831a720d64390b20bce528)
2023-06-07 19:17:19.437 30100-30100 DEBUG                   pid-30100                            A        #04 pc 00029030  /data/app/com.bigfoot.raymob-C4cpo3DmbcWDyt4Gn3_5yA==/base.apk!libraymob.so (offset 0x41000) (android_main+136) (BuildId: 9478e2f21e71debedf831a720d64390b20bce528)
2023-06-07 19:17:19.437 30100-30100 DEBUG                   pid-30100                            A        #05 pc 00010b51  /data/app/com.bigfoot.raymob-C4cpo3DmbcWDyt4Gn3_5yA==/base.apk!libraymob.so (offset 0x41000) (BuildId: 9478e2f21e71debedf831a720d64390b20bce528)

And the second solution:

	while (fileDataPtr < endfileDataPtr)
	{

		char szChunkName[5] = { 0 };
		memcpy(szChunkName, fileDataPtr, 4);
		szChunkName[4] = 0;
		fileDataPtr += 4;
		
		[...]

Here is its result, it crashed after 3391 iterations at the memcpy level:

2023-06-07 19:01:31.106 27235-27282 DEBUG - Vo...omMemory() com.bigfoot.raymob                   I  START ITERATION 3391 IN `while (fileDataPtr < endfileDataPtr)`
2023-06-07 19:01:31.107 27235-27282 libc                    com.bigfoot.raymob                   A  Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x1350e9f9 in tid 27282 (.bigfoot.raymob), pid 27235 (.bigfoot.raymob)
2023-06-07 19:01:31.269 27288-27288 DEBUG                   pid-27288                            A  pid: 27235, tid: 27282, name: .bigfoot.raymob  >>> com.bigfoot.raymob <<<
2023-06-07 19:01:31.275 27288-27288 DEBUG                   pid-27288                            A        #00 pc 0008a3ac  /data/app/com.bigfoot.raymob-uTazoBRUOXL9lGvCIUk-ig==/base.apk!libraymob.so (offset 0x41000) (Vox_LoadFromMemory+412) (BuildId: dfe8dee206b040b8d04fd1f143df2d6fb975feaf)
2023-06-07 19:01:31.275 27288-27288 DEBUG                   pid-27288                            A        #01 pc 000a8fec  /data/app/com.bigfoot.raymob-uTazoBRUOXL9lGvCIUk-ig==/base.apk!libraymob.so (offset 0x41000) (BuildId: dfe8dee206b040b8d04fd1f143df2d6fb975feaf)
2023-06-07 19:01:31.275 27288-27288 DEBUG                   pid-27288                            A        #02 pc 000a4ae8  /data/app/com.bigfoot.raymob-uTazoBRUOXL9lGvCIUk-ig==/base.apk!libraymob.so (offset 0x41000) (LoadModel+284) (BuildId: dfe8dee206b040b8d04fd1f143df2d6fb975feaf)
2023-06-07 19:01:31.275 27288-27288 DEBUG                   pid-27288                            A        #03 pc 0000f8b9  /data/app/com.bigfoot.raymob-uTazoBRUOXL9lGvCIUk-ig==/base.apk!libraymob.so (offset 0x41000) (main+320) (BuildId: dfe8dee206b040b8d04fd1f143df2d6fb975feaf)
2023-06-07 19:01:31.275 27288-27288 DEBUG                   pid-27288                            A        #04 pc 00029030  /data/app/com.bigfoot.raymob-uTazoBRUOXL9lGvCIUk-ig==/base.apk!libraymob.so (offset 0x41000) (android_main+136) (BuildId: dfe8dee206b040b8d04fd1f143df2d6fb975feaf)
2023-06-07 19:01:31.275 27288-27288 DEBUG                   pid-27288                            A        #05 pc 00010b51  /data/app/com.bigfoot.raymob-uTazoBRUOXL9lGvCIUk-ig==/base.apk!libraymob.so (offset 0x41000) (BuildId: dfe8dee206b040b8d04fd1f143df2d6fb975feaf)
2023-06-07 19:01:33.435 27235-27235 threaded_app            com.bigfoot.raymob                   V  Pause: 0xda6a00a0
2023-06-07 19:01:33.591  1223-1356  InputDispatcher         system_server                        E  channel 'c5a0ab9 com.bigfoot.raymob/com.bigfoot.raymob.NativeLoader (server)' ~ Channel is unrecoverably broken and will be disposed!

I also had a freeze of the app at one time with these logs, I'm sorry, I hadn't noted it was with what solution and I have a doubt now:

2023-06-07 18:54:50.573 25854-25959 DEBUG - Vo...omMemory() com.bigfoot.raymob                   I  START ITERATION 385959 IN `while (fileDataPtr < endfileDataPtr)`
2023-06-07 18:54:50.573 25854-25959 DEBUG - Vo...omMemory() com.bigfoot.raymob                   I  `memcpy(szChunkName, fileDataPtr, 4)` IS DONE
2023-06-07 18:54:50.573 25854-25959 DEBUG - Vo...omMemory() com.bigfoot.raymob                   I  LETS CHECK CHUNK
2023-06-07 18:54:50.573 25854-25959 DEBUG - Vo...omMemory() com.bigfoot.raymob                   I  NO MATCH FOUND
read: unexpected EOF!

Otherwise, regardless of the error, the crash never occurs after the same number of iterations but always at the level of memcpy or strcmp | strncmp.

To be sure, I specify the procedure: I recompile raylib, I replace the libraylib.a file of the project, I "clean" the project, I completely "rebuild" the project to be sure, and I recompile by doing "run" .

@bztsrc Thank you very much for the suggestion, I'll see that for my project :)

@raysan5
Copy link
Owner

raysan5 commented Jun 7, 2023

@Bigfoot71 Sorry to read it neither worked... I'm afraid at this point we can assume this issue is out-of-scope of raylib, no idea why it crashes...

@Bigfoot71
Copy link
Contributor Author

Bigfoot71 commented Jun 7, 2023

I'm still going to keep looking for a bit. Out of spite I rewrote all the necessary code with different function names directly in the main.c and I replaced the strcmp with index by index checks and I also rewrote a very dirty memcpy in using a simple for loop, all hoping to have a little more control over the situation.

Here is the error I got, it became SEGV_MAPERR again, so we are trying to access an unallocated memory area, and this time the logs explicitly tell me that the error occurs in memcpy:

2023-06-07 21:45:41.149 22107-22143 libc                    com.bigfoot.raymob                   A  Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xb3a0200f in tid 22143 (.bigfoot.raymob), pid 22107 (.bigfoot.raymob)
2023-06-07 21:45:41.258 22150-22150 DEBUG                   pid-22150                            A  pid: 22107, tid: 22143, name: .bigfoot.raymob  >>> com.bigfoot.raymob <<<
2023-06-07 21:45:41.263 22150-22150 DEBUG                   pid-22150                            A        #00 pc 0000f800  /data/app/com.bigfoot.raymob-sq5O8dfc8BGamEHVOCs6SA==/base.apk!libraymob.so (offset 0x12f000) (my_memcpy+36) (BuildId: 462a4be4220283995653e1e791e1956c33b09761)
2023-06-07 21:45:41.263 22150-22150 DEBUG                   pid-22150                            A        #01 pc 000102fb  /data/app/com.bigfoot.raymob-sq5O8dfc8BGamEHVOCs6SA==/base.apk!libraymob.so (offset 0x12f000) (BuildId: 462a4be4220283995653e1e791e1956c33b09761)
2023-06-07 21:45:41.263 22150-22150 DEBUG                   pid-22150                            A        #02 pc 0000fe57  /data/app/com.bigfoot.raymob-sq5O8dfc8BGamEHVOCs6SA==/base.apk!libraymob.so (offset 0x12f000) (BuildId: 462a4be4220283995653e1e791e1956c33b09761)
2023-06-07 21:45:41.263 22150-22150 DEBUG                   pid-22150                            A        #03 pc 0000f965  /data/app/com.bigfoot.raymob-sq5O8dfc8BGamEHVOCs6SA==/base.apk!libraymob.so (offset 0x12f000) (main+332) (BuildId: 462a4be4220283995653e1e791e1956c33b09761)
2023-06-07 21:45:41.263 22150-22150 DEBUG                   pid-22150                            A        #04 pc 0002a280  /data/app/com.bigfoot.raymob-sq5O8dfc8BGamEHVOCs6SA==/base.apk!libraymob.so (offset 0x12f000) (android_main+136) (BuildId: 462a4be4220283995653e1e791e1956c33b09761)
2023-06-07 21:45:41.263 22150-22150 DEBUG                   pid-22150                            A        #05 pc 00011d9d  /data/app/com.bigfoot.raymob-sq5O8dfc8BGamEHVOCs6SA==/base.apk!libraymob.so (offset 0x12f000) (BuildId: 462a4be4220283995653e1e791e1956c33b09761)

Here is my version of memcpy, don't laugh, at least it's self-explanatory:

void my_memcpy(void* destination, const void* source, size_t nb_bytes) {
    char* dest = (char*)destination;
    const char* src = (const char*)source;
    for (size_t i = 0; i < nb_bytes; i++) {
        dest[i] = src[i];
    }
}

If anyone has an idea, even if it seems stupid, don't hesitate!
I'm going to think about it for another 2 days, if it's not settled by then, then I'll close this strange issue.

Edit: By fumbling and testing everything and anything (at this point, weird problem, weird solution) I changed the loop that loads the colors:

//(each pixel: 1 byte x 4 : r, g, b, a ) x 256
for (int i = 0; i < 256 - 1; i++)
{
	col.r = *((unsigned char*)fileDataPtr++);
	col.g = *((unsigned char*)fileDataPtr++);
	col.b = *((unsigned char*)fileDataPtr++);
	col.a = *((unsigned char*)fileDataPtr++);

	pvoxarray->palette[i + 1] = col;
}

In this (instead of filling palette from 1 to 255 I fill it from 0 to 255):

//(each pixel: 1 byte x 4 : r, g, b, a ) x 256
for (int i = 0; i < 256; i++)
{
	col.r = *((unsigned char*)fileDataPtr++);
	col.g = *((unsigned char*)fileDataPtr++);
	col.b = *((unsigned char*)fileDataPtr++);
	col.a = *((unsigned char*)fileDataPtr++);

	pvoxarray->palette[i] = col;
}

And there is no more error at all, it opens every time but obviously the colors are incorrect. Am I losing my mind or is this the beginning of a sign of logic?

I also did tests by putting breakpoints everywhere but nothing very meaningful, everything seems perfectly normal at first sight, even before the crashes.

@fxgenstudio
Copy link
Contributor

That work under your android when you change palette loop ?

@Bigfoot71
Copy link
Contributor Author

@fxgenstudio Yes exactly, it works when I run it from 0 to 255 rather than 1 to 255 but the colors of the models are incorrect

@fxgenstudio
Copy link
Contributor

Ok great news !
You need to revert your loop modifications and increase palette array size

@Bigfoot71
Copy link
Contributor Author

Bigfoot71 commented Jun 8, 2023

I already did it unfortunately, I put [257], [512] and even [1024] out of desperation, and I fell back on the same errors as before

@fxgenstudio
Copy link
Contributor

Maybe a memory alignment problem.
You could move "VoxColor col;" at top of function ?

@Bigfoot71
Copy link
Contributor Author

Yes, I just did it but no positive results

@Bigfoot71
Copy link
Contributor Author

Bigfoot71 commented Jun 9, 2023

Well, I've tried many things again but without success. I had my friends try the same app that crashes on my device, and strangely, it doesn't crash for them. It must be related to my device, I don't know...

So we can be sure that this is "out-of-scope of raylib", as mentioned by @raysan5. Therefore, I will close this issue, as it doesn't really belong here.

As a conclusion, I will still avoid using this file format for Android with raylib, despite its advantages, because if it happens to me, it may potentially happen to other users as well.

Nevertheless, I want to thank you for your patience and all your help!

@Bigfoot71 Bigfoot71 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external This issue depends on external lib
Projects
None yet
Development

No branches or pull requests

5 participants