artoolkitx / arunityx

artoolkitX for Unity, providing high-performance video acquisition, marker and texture tracking and full Unity Editor support
https://www.artoolkitx.org/
Other
41 stars 22 forks source link

Editor Crashing in Windows #22

Closed OptrixAU closed 1 year ago

OptrixAU commented 4 years ago

Tried in 2018.4 and 2019.1

Tried using the files provided in the official release UnityPackage, and files taken from the latest commit.

Used the ARX dll that came with the package, and the ARX DLL that is in the latest version of ARToolkitX. Used the OpenGL DLLs found in the ARX package.

Brand-new, clean project.

HOWEVER - please note that I'm also having trouble getting the samples included with the Windows ARToolkitX demo working. They all report the following...

[error] Error: a required OpenGL function counld not be bound. [error] Error initializing display of video frames from source. [error] Unable to init ARVideoView. [error] Error in ARController::drawVideoSettings()

This might be something completely different, since it appears to be in the PRESENTATION of the information. However, I've reported this on the artoolkitx issues list.

OptrixAU commented 4 years ago

OK - the crash is happening in getFrameTextureRGBA32, called from ARController::UpdateTexture. This is using the latest branch that runs correctly on Windows. It's an "Attempt to access invalid address" crash - probably a null-reference exception occuring somewhere in that function.

It's after the scene has been configured for video, on the render of the first real video frame.

OptrixAU commented 4 years ago

Without "UpdateTexture", the crash is removed. Tracking works (even though the screen is blank, a marker held up to the camera tracks in 3D space) so all other functions appear to work.

It's something to do exclusively with transferring the camera image from ARToolkit to Unity.

OptrixAU commented 4 years ago

The ARToolkitX code looks almost identical to what is used in ARToolkit5, so it's a little confusing.

Unity is sending a 921,600-pixel buffer to the function, and I added some debug text ARX.dll which confirmed that it's expecting a 32-bit 1280x720 image - the buffer would appear to be the correct size.

Just in case there was an issue with it, I tried replacing the GCHandle object on the Unity side of arwUpdateTexture32 to use a NativeArray and enabled unsafe code, but it resulted in the same crash.

It's as if for some reason the videoRGBA function in artoolkitX is writing to memory outside the pointer we are passing? Going to add some more debug lines to ARToolkit to see if I can verify that.

OptrixAU commented 4 years ago

Crash appears to be caused by the video format - If I add "-format=BGRA" to the video config strings (taken from the defaults in ARToolkit5-Unity), no crash occurs. The crash happens if the cameras native format (AR_PIXEL_FORMAT_420f) is used.

I would suggest making the default camera config for Windows include a '-format' directive to avoid the issue in the future. This might have something to do with the removal of the Windows Store configuration strings?