effekseer / EffekseerForCocos2d-x

MIT License
42 stars 18 forks source link

TransformVertexes SSE2 issue #7

Closed kalibannez closed 5 years ago

kalibannez commented 5 years ago

Hi, I think that i found bug in inline void TransformVertexes( Vertex* vertexes, int32_t count, const ::Effekseer::Matrix43& mat ) function in EFK_SSE2 section. When i debugging my game with enabled Address Sanitizer under OS X with cocos2d-x effekseer, i'm getting following error: `================================================================= ==69543==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffeefbf9263 at pc 0x0001037887f3 bp 0x7ffeefbf8870 sp 0x7ffeefbf8868 READ of size 16 at 0x7ffeefbf9263 thread T0

0 0x1037887f2 in EffekseerRendererGL::TransformVertexes(EffekseerRendererGL::Vertex*, int, Effekseer::Matrix43 const&) EffekseerRendererNative.cpp:849

#1 0x1037830cc in void EffekseerRenderer::SpriteRendererBase<EffekseerRendererGL::RendererImplemented, EffekseerRendererGL::Vertex, EffekseerRendererGL::VertexDistortion>::Rendering_Internal<EffekseerRendererGL::Vertex>(Effekseer::SpriteRenderer::NodeParameter const&, Effekseer::SpriteRenderer::InstanceParameter const&, void*, Effekseer::Matrix44 const&) EffekseerRendererNative.h:2911
#2 0x103778f11 in EffekseerRenderer::SpriteRendererBase<EffekseerRendererGL::RendererImplemented, EffekseerRendererGL::Vertex, EffekseerRendererGL::VertexDistortion>::Rendering_(Effekseer::SpriteRenderer::NodeParameter const&, Effekseer::SpriteRenderer::InstanceParameter const&, void*, Effekseer::Matrix44 const&) EffekseerRendererNative.h:2763
#3 0x1037759dc in EffekseerRenderer::SpriteRendererBase<EffekseerRendererGL::RendererImplemented, EffekseerRendererGL::Vertex, EffekseerRendererGL::VertexDistortion>::Rendering(Effekseer::SpriteRenderer::NodeParameter const&, Effekseer::SpriteRenderer::InstanceParameter const&, void*) EffekseerRendererNative.h:3012
#4 0x10098153f in Effekseer::EffectNodeSprite::Rendering(Effekseer::Instance const&, Effekseer::Instance const*, Effekseer::Manager*) EffekseerNative.cpp:11260
#5 0x1009d690a in Effekseer::Instance::Draw(Effekseer::Instance*) EffekseerNative.cpp:16081
#6 0x1009c77d2 in Effekseer::InstanceContainer::Draw(bool) EffekseerNative.cpp:14737
#7 0x1009cddbe in Effekseer::ManagerImplemented::DrawHandle(int) EffekseerNative.cpp:14227
#8 0x1022a50bb in efk::EffectEmitter::draw(cocos2d::Renderer*, cocos2d::Mat4 const&, unsigned int)::$_0::operator()() const Effekseer.cpp:610
#9 0x1022a477c in void std::__1::__invoke_void_return_wrapper<void>::__call<efk::EffectEmitter::draw(cocos2d::Renderer*, cocos2d::Mat4 const&, unsigned int)::$_0&>(efk::EffectEmitter::draw(cocos2d::Renderer*, cocos2d::Mat4 const&, unsigned int)::$_0&&&) type_traits:4428
#10 0x1022a4618 in std::__1::__function::__func<efk::EffectEmitter::draw(cocos2d::Renderer*, cocos2d::Mat4 const&, unsigned int)::$_0, std::__1::allocator<efk::EffectEmitter::draw(cocos2d::Renderer*, cocos2d::Mat4 const&, unsigned int)::$_0>, void ()>::operator()() functional:1562
#11 0x1001268a1 in std::__1::function<void ()>::operator()() const functional:1913
#12 0x1014bd590 in cocos2d::CustomCommand::execute() CCCustomCommand.cpp:55
#13 0x103665932 in cocos2d::Renderer::processRenderCommand(cocos2d::RenderCommand*) CCRenderer.cpp:480
#14 0x10366adf2 in cocos2d::Renderer::visitRenderQueue(cocos2d::RenderQueue&) CCRenderer.cpp:618
#15 0x10366c143 in cocos2d::Renderer::render() CCRenderer.cpp:680
#16 0x10264a549 in cocos2d::Scene::render(cocos2d::Renderer*) CCScene.cpp:277
#17 0x1007085e1 in cocos2d::Director::drawScene() CCDirector.cpp:339
#18 0x100733d6d in cocos2d::DisplayLinkDirector::mainLoop() CCDirector.cpp:1490
#19 0x10328dd8d in cocos2d::Application::run() CCApplication-mac.mm:111
#20 0x103288e40 in main main.mm:144
#21 0x7fff7d485ed8 in start (libdyld.dylib:x86_64+0x16ed8)

I think, the reason of that is _mm_loadu_ps function works with four values (as described there https://software.intel.com/en-us/node/524260), but TransformVertexes function corresponding Matrix43 matrix. I mean, that call_mm_loadu_ps( mat.Value[0] )uses mat.Value[0][0], mat.Value[0][1], mat.Value[0][2], mat.Value[1][0], call_mm_loadu_ps( mat.Value[1] )uses mat.Value[1][0], mat.Value[1][1], mat.Value[1][2], mat.Value[2][0] and so on. And_mm_loadu_ps( mat.Value[3] )` approach stack overflow.

Could you fix it, please?

durswd commented 5 years ago

Thank you I'm going to fix it

durswd commented 5 years ago

I fixed it But I only tested on windows and android. I will test on Mac few days ago Please try it.

https://github.com/effekseer/EffekseerForCocos2d-x/commit/be5f2695994e69c28ef5f2f936d27a1480b05ca5

durswd commented 5 years ago

Fixed it

kalibannez commented 5 years ago

Now it works on Mac, thank you!