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

Maximum stack exceed when running on WEB....(runned your example code in web) #1

Closed
KaushickSArgekar opened this issue Oct 14, 2021 · 8 comments

Comments

@KaushickSArgekar
Copy link

The following JSRangeError was thrown building MyApp(dirty):
Invalid argument: Maximum call stack size exceeded

The relevant error-causing widget was
MyApp
lib/main.dart:30
When the exception was thrown, this was the stack
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 829:8 get

@marcglasberg
Copy link
Owner

Ok, really weird. I haven't tested it on the web, though. Will do that soon as let you know.

@nullrocket
Copy link

I'm seeing the same thing. I narrowed it down somewhat, accessing super.hashCode throws the error, just trying to print the value will cause the same exception.

int get hashCode => super.hashCode ^ id.hashCode ^ defaultColor.hashCode;

I tried cutting out much of the Themed class out and narrowing it down more but haven't been able to yet.

Another issue that I am seeing here in the value getter this also throws an error when trying to access it. You can try adding a print statement to see it throw.

Color? result = _currentTheme[this] as Color?;

@nullrocket
Copy link

A little more investigation points to extending Color somehow being the issue. If I create a mock Color class and substitute it for Color everything "works" you can access super and this in overridden methods on ColorRef , using the real class throws an error. I think this is probably a bug at the flutter level, but I don't know for sure.

@nullrocket
Copy link

Could this be related?
flutter/flutter#43533

marcglasberg added a commit that referenced this issue Oct 22, 2021
@marcglasberg
Copy link
Owner

@KaushickSArgekar @nullrocket

Could you please tell me if this is fixed in version 2.1.0?

@arthurdelight4
Copy link

@marcglasberg - It's working for me (I ran into the same issue). Nice work! I'm really enjoying this library.

@nullrocket
Copy link

@marcglasberg
It is working and I did figure out why I couldn't print the this value within the value getter, it doesn't affect the code as intended to be used, and wasn't a mysterious bug :) but I feel kinda dumb about spending so much time looking at it now.

The default toString method on Color relies on value to print its string, accessing it indirectly from within ColorRef's value getter by printing triggered a recursive set of calls to value. I did override toString for ColorRef just to not be hit by something similar if I did some quick print() debugging later on.

  @override
  int get value {
    // trying to print calls Color.toString which throws the maximum stack exceeded error,
    // because Color's default toString method tries to access value which then recursively calls print / value print / value to
    // infinity.
    print(this);
    Color? result = _currentTheme[this] as Color?;
    result ??= _defaultTheme[this] as Color?;

    result ??= defaultColor;
    if (result == null) throw ConstThemeException('Theme color "$id" is not defined.');
    if (_transformColor != null) result = _transformColor!(result);
    return result.value;
  }

Maybe you could add a toString method to the ColorRef class? Right now printing a ColorRef or calling toString is going to tell you that you have a Color(0x..) class and not a ColorRef.

  @override
  String toString() {
    return "ColorRef('$defaultColor', id: '$id' )";
  }

@marcglasberg
Copy link
Owner

@nullrocket Thanks for the idea. Please see version 2.2.0: Improved ColorRef.toString() and TextStyleRef.toString() methods.

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

No branches or pull requests

4 participants