axmolengine / axmol

Axmol Engine – A Multi-platform Engine for Desktop, XBOX (UWP) and Mobile games. (A fork of Cocos2d-x-4.0)
https://axmol.dev
MIT License
868 stars 195 forks source link

Sprite::initWithFile wrong #1374

Closed NgVThangBz closed 11 months ago

NgVThangBz commented 11 months ago

Screenshot 2023-10-05 at 16 31 37

im check, in Image::initWithImageData, not can init, and i check in app data exist file image. (my code run good in cocos2dx 3.17) so please check it. save a image and load it

halx99 commented 11 months ago

reproduce steps and sample?

NgVThangBz commented 11 months ago

@halx99 , you can try that: save image to appdata and reload image

Screenshot 2023-10-06 at 08 36 06

_spriteView = new Sprite; std::string fullPath = FileUtils::getInstance()->getWritablePath() + "checkImage.jpg"; utils::captureScreen([=](bool is, std::string_view name){ _spriteView->initWithFile(name); },fullPath);

Am I using the wrong api? I tried it on cocos2dx, and it seems to work fine

rh101 commented 11 months ago

@NgVThangBz By your screenshots, you seem to be familiar with the debugger, so what is preventing you from stepping through the code to find out why it is not behaving as it should?

For instance, what is the value of name that is passed into _spriteView->initWithFaile(name) in the captureScreen callback? Show what it actually is, and what you expect it to be. Do the same test on Cocos2d-x to find out what the difference is, and actually add this type of information in your posts. You can keep stepping through the code in the debugger until it goes through the FileUtils methods, and then you can see exactly what is happening in there; the code is relatively straightforward.

Providing vague or incomplete information, and with what appears to be little effort on your side, is not the best way to motivate others in helping you solve a problem.

NgVThangBz commented 11 months ago

@rh101 As I mentioned at the beginning, I debugged inside and found something wrong with TextureCache::addImage, and I see _textures.find(fullpath); cannot find, and in cocos it runs

rh101 commented 11 months ago

@rh101 As I mentioned at the beginning, I debugged inside and found something wrong with TextureCache::addImage, and I see _textures.find(fullpath); cannot find, and in cocos it runs

I understand, but you seem to have stopped short of stepping into the code that tries to load the file, and to see why it isn't working as you expect it to.

The engine code isn't a mystery, it's right there for all to see, and spending a few extra minutes stepping into it may help you find the answers you're looking for, or at the very least more insight into the issue that would allow you to provide more detailed information about any possible problem. That little bit of extra effort would save other people a significant amount of time in helping you solve issues like this.

halx99 commented 11 months ago

I can't reproduce, more info?

NgVThangBz commented 11 months ago

@halx99, bạn có thể thử: lưu hình ảnh vào dữ liệu ứng dụng và tải lại hình ảnh

Ảnh chụp màn hình 2023-10-06 lúc 08 36 06

_spriteView = Sprite mới; std::string fullPath = FileUtils::getInstance()->getWritablePath() + "checkImage.jpg"; utils::captureScreen([=](bool is, std::string_view name){ _spriteView->initWithFile(name); },fullPath);

@halx99 you try that right?

halx99 commented 11 months ago

yes, woked

NgVThangBz commented 11 months ago

yes, woked

sr,i check it agian this is my error, im set scaleY when _texture not yet init, Sorry for disturbing