Coder Social home page Coder Social logo

Comments (6)

kestrelm avatar kestrelm commented on May 28, 2024 1

Hello,

Thanks so much for diagnosing and looking into the problem! This is very strange though since I could not replicate it on my end; however I am on MSVC2015 and I believe the studios deploying it as on it as well. However, I need to double check again to make sure they are not having the same issues. The CreaturePack function was just recently introduced into Cocos2d-x so there might have been some initial deployment issues like the one you uncovered. Thanks so much again for your valuable time!

Cheers

from creature_cocos2dx.

kestrelm avatar kestrelm commented on May 28, 2024

Hello,

Sorry but I am not sure why this is happening, the CreaturePack plugin is being successfully deployed by various studios as we speak on Android, ios and PC platforms.

I just ran a test and it ran on my rig as well. Can it be because packloader is going out of scope in your code and hence a memory error is happening? Do you want to try moving packloader to a more global location where it does not go out of scope?

from creature_cocos2dx.

NuLL3rr0r avatar NuLL3rr0r commented on May 28, 2024

Hello,

Thanks for the quick reply. This seems very odd to me too. I doubt that this is due to packloader going out of scope. When I comment this line:

auto raw_bytes = std::vector<uint8_t>((std::istreambuf_iterator<uint8_t>(file)),
            std::istreambuf_iterator<uint8_t>());

and initialize the smartpointer using the CreaturePackLoader() constructor with zero parameters it won't throw.

return std::shared_ptr<CreaturePackLoader>(new CreaturePackLoader());

But, I'll try to make packloader global and give it another go and report back.

It might be that our animator made a mistake or something during the export (I'm not sure of this since it works on UE4 creature pack plugin). Unfortunately, I don't have the original project files nor the Creature Editor installed on my PC. I'll see her in 2/3 days and try to export it myself on her laptop and run another test.

from creature_cocos2dx.

NuLL3rr0r avatar NuLL3rr0r commented on May 28, 2024

I just made packloader global and ran another test. Unfortunately, results are the same.

A quick question. Should I copy anything else besides .creature_pack and .png files to the Resources folder?

from creature_cocos2dx.

NuLL3rr0r avatar NuLL3rr0r commented on May 28, 2024

After spending some time on this issue, I believe I found the root of the issue. The issue is std::basic_ifstream<uint8_t>. Please take a look at this stackoverflow question.

There are three possible methods to read the file correctly. I ran a benchmark and created a pull request using the fastest possible method to read the binary creature_pack file into a std::vector. It builds and runs fine on both LLVM/Clang and GCC. It loads the mesh and plays the animation. I'll attach all test cases for your perusal with a few comments.

/// Slowest version on both clang and gcc
/// the key here to not get that std::bad_cast is
/// file.unsetf(std::ios::skipws);

#include <chrono>
#include <fstream>
#include <ios>
#include <iostream>
#include <iterator>
#include <vector>
#include <cstdint>

int main()
{
    auto start = std::chrono::high_resolution_clock::now();

    // open the file:
    std::ifstream file("naser_character_data.creature_pack", std::ios::binary);

    // Stop eating new lines in binary mode!!!
    file.unsetf(std::ios::skipws);

    // get its size:
    file.seekg(0, std::ios::end);
    const std::streampos fileSize = file.tellg();
    file.seekg(0, std::ios::beg);

    // reserve capacity
    std::vector<uint8_t> raw_bytes;
    raw_bytes.reserve(fileSize);

    // read the data:
    raw_bytes.insert(raw_bytes.begin(),
                     std::istream_iterator<uint8_t>(file),
                     std::istream_iterator<uint8_t>());

    auto finish = std::chrono::high_resolution_clock::now();

    auto microseconds = std::chrono::duration_cast<std::chrono::microseconds>(finish-start);
    std::cout << microseconds.count() << "µs" << std::endl;

    return 0;
}
/// Slightly faster on both clang and gcc
/// note if I use uint8_t which is unsigned char we will get that std::bad_cast
/// even though we are reading an unsigned char it is ok to read it as char.
/// also, note that int8_t defined as signed char which gives me compile errors.
/// but char is OK.

#include <chrono>
#include <fstream>
#include <ios>
#include <iostream>
#include <iterator>
#include <vector>
#include <cstdint>

int main()
{
    auto start = std::chrono::high_resolution_clock::now();

    // open the file:
    std::ifstream file("naser_character_data.creature_pack", std::ios::binary);

    // read the data:
    std::vector<uint8_t> raw_bytes((std::istreambuf_iterator<char>(file)),
                                   std::istreambuf_iterator<char>());

    auto finish = std::chrono::high_resolution_clock::now();

    auto microseconds = std::chrono::duration_cast<std::chrono::microseconds>(finish-start);
    std::cout << microseconds.count() << "µs" << std::endl;

    return 0;
}
/// The fastest method on both clang and gcc using std::copy
/// the pull request uses this method

#include <chrono>
#include <fstream>
#include <ios>
#include <iostream>
#include <iterator>
#include <vector>
#include <cstdint>

int main()
{
    auto start = std::chrono::high_resolution_clock::now();

    // open the file:
    std::ifstream file("naser_character_data.creature_pack", std::ios::binary);

    // Stop eating new lines in binary mode!!!
    file.unsetf(std::ios::skipws);

    // get its size:
    file.seekg(0, std::ios::end);
    const std::streampos fileSize = file.tellg();
    file.seekg(0, std::ios::beg);

    // reserve capacity
    std::vector<uint8_t> raw_bytes;
    raw_bytes.reserve(fileSize);

    // read the data:
    std::copy(std::istream_iterator<uint8_t>(file),
              std::istream_iterator<uint8_t>(),
              std::back_inserter(raw_bytes));

    auto finish = std::chrono::high_resolution_clock::now();

    auto microseconds = std::chrono::duration_cast<std::chrono::microseconds>(finish-start);
    std::cout << microseconds.count() << "µs" << std::endl;

    return 0;
}

Hope that helps.

from creature_cocos2dx.

NuLL3rr0r avatar NuLL3rr0r commented on May 28, 2024

Great! that is good news, good to hear CreaturePack has been integrated into Cocos2d-x.

Keep up the good work!

from creature_cocos2dx.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.