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

fixed memory leak on x86 android devices. #17172

Merged
merged 3 commits into from
Jun 18, 2024

Conversation

dumganhar
Copy link
Contributor

Re: #

https://forum.cocos.org/t/topic/158470

Changelog


Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

@dumganhar dumganhar requested review from minggo and star-e June 17, 2024 10:22
Copy link

Interface Check Report

This pull request does not change any public interfaces !

@dumganhar
Copy link
Contributor Author

@cocos-robot run test cases

@@ -1396,7 +1400,7 @@ struct ALIGNAS(8) BufferBarrierInfo {

uint32_t offset{0};
uint32_t size{0};

uint32_t _padding{0};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot the padding changed member initialization order. It can be problematic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we depend on the order?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have searched the codebase and it seems aggregate initialization is not used.
So it might be fine.

@star-e star-e self-requested a review June 17, 2024 11:47
Copy link

@dumganhar, Please check the result of run test cases:

Task Details

Platform build boot runned crashScene FailScene
ios PASS PASS FAIL
mac PASS PASS PASS

Copy link

@dumganhar, Please check the result of run test cases:

Task Details

Platform build boot runned crashScene FailScene
web-mobile PASS PASS FAIL scroll-view-scroll-to-offset,particle-2d-normal,perspective-ui
windows PASS PASS PASS
android PASS PASS FAIL SpineMesh,particle-2d-normal,perspective-ui

@dumganhar dumganhar merged commit 6d7cfb1 into cocos:v3.8.5 Jun 18, 2024
24 checks passed

// Macro definition to check if a type has padding
#define CC_CHECK_STRUCT_NO_PADDING(T) \
static_assert(std::has_unique_object_representations_v<T>, "ERROR: Type has padding bytes!")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can not use std::has_unique_object_representations_v<T> to check padding, as in the following codes, it also returns false

struct D {
    int* ptr;
};

struct E {
    int id;
    std::string name;
    double* data;
};

Will return false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could work for primitve types, and all gfx structs that need the added padding manually could work by std:: has_unique_object_representations_v

So do we need to consider stl containers, like string, vector, list, map in struct?
And if so , any suggestion for how to check those types?

Copy link
Contributor Author

@dumganhar dumganhar Jun 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example you wrote:

struct D {
    int* ptr;
};

returns true.

You could paste code

#include <type_traits>
#include <stdint.h>
#include <iostream>
#include <cstddef> 

#define CHECK_NO_PADDING(T) \
    static_assert(std::has_unique_object_representations_v<T>, "Type " #T " has padding bytes!")


struct D {
    int* ptr;
};

struct E {
    int id;
    std::string name;
    double* data;
};

int main() {

  
  CHECK_NO_PADDING(D); // return true, since int* is 4 bytes,  the default padding is 4 bytes too.
  CHECK_NO_PADDING(E);  // return false, 
   

    return 0;
}

in cpp.sh to test. The environment on cpp.sh is x86 .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So do we need to consider stl containers, like string, vector, list, map in struct?
And if so , any suggestion for how to check those types?

It depends on the usage. But as this function is defined in Macros.h, so should add comments to say that it only works for primitive types.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct D {
int* ptr;
};
returns true.

Yep, i was deceived by ChatGPT.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add a comment later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants